In Poling.scala function def run() -> wrap handleUpdate in Future
rema7 opened this issue · 3 comments
May be it's a good idea to wrap handleUpdate in a Future object
Because getUpdates return Future[Array] and increment of a updateOffset value happens after update will be handled.
It lead to if getUpdates return more then 1 item and/or handle will take more then 1 second, getUpdate will call again with same updateOffset value.
override def run(): Unit = {
// setWebhook(None)
var updatesOffset = 0
while (running) {
for (updates <- getUpdates(offset = updatesOffset)) {
for (u <- updates ) {
Future(handleUpdate(u))
updatesOffset = updatesOffset max (u.updateId + 1)
}
}
Thread.sleep(pollingCycle)
}
}
Thanks, you are 200% right. In the initial design getUpdates wasn't async, so the updates were processed correctly in arrival order. Your solution LGTM, feel free to send a PR, or if you are motivated you can reshape the whole "run" method to make it rock solid. A big updater/refactor is coming soon, I'll make sure to be careful with the asyncness.
@mukel, update your package on oss.sonatype.org, please
Done!