Workaround for multiple `waitFor` where `await` must be used.

Bump version to 2.0.7.
This commit is contained in:
cheatfate 2018-08-06 15:15:05 +03:00
parent 293f993bed
commit 7718ebe1ee
2 changed files with 7 additions and 1 deletions

View File

@ -1,5 +1,5 @@
packageName = "asyncdispatch2"
version = "2.0.6"
version = "2.0.7"
author = "Status Research & Development GmbH"
description = "Asyncdispatch2"
license = "Apache License 2.0 or MIT"

View File

@ -227,6 +227,12 @@ template processTimers(loop: untyped) =
template processCallbacks(loop: untyped) =
var count = len(loop.callbacks)
for i in 0..<count:
# This is mostly workaround for people which are using `waitFor` where
# it must be used `await`. While using `waitFor` inside of callbacks
# dispatcher's callback list is got decreased and length of
# `loop.callbacks` become not equal to `count`, its why `IndexError`
# can be generated.
if len(loop.callbacks) == 0: break
let callable = loop.callbacks.popFirst()
callable.function(callable.udata)