Fixes asyncdispatch.all completing its res future more than once.
This commit is contained in:
parent
e6f6323e77
commit
c538e1ae08
1 changed files with 15 additions and 14 deletions
|
|
@ -263,13 +263,13 @@ proc all*[T](futs: varargs[Future[T]]): auto =
|
||||||
|
|
||||||
for fut in futs:
|
for fut in futs:
|
||||||
fut.callback = proc(f: Future[T]) =
|
fut.callback = proc(f: Future[T]) =
|
||||||
if f.failed:
|
inc(completedFutures)
|
||||||
retFuture.fail(f.error)
|
if not retFuture.finished:
|
||||||
elif not retFuture.finished:
|
if f.failed:
|
||||||
inc(completedFutures)
|
retFuture.fail(f.error)
|
||||||
|
else:
|
||||||
if completedFutures == totalFutures:
|
if completedFutures == totalFutures:
|
||||||
retFuture.complete()
|
retFuture.complete()
|
||||||
|
|
||||||
if totalFutures == 0:
|
if totalFutures == 0:
|
||||||
retFuture.complete()
|
retFuture.complete()
|
||||||
|
|
@ -285,14 +285,15 @@ proc all*[T](futs: varargs[Future[T]]): auto =
|
||||||
for i, fut in futs:
|
for i, fut in futs:
|
||||||
proc setCallback(i: int) =
|
proc setCallback(i: int) =
|
||||||
fut.callback = proc(f: Future[T]) =
|
fut.callback = proc(f: Future[T]) =
|
||||||
if f.failed:
|
inc(completedFutures)
|
||||||
retFuture.fail(f.error)
|
if not retFuture.finished:
|
||||||
elif not retFuture.finished:
|
if f.failed:
|
||||||
retValues[i] = f.read()
|
retFuture.fail(f.error)
|
||||||
inc(completedFutures)
|
else:
|
||||||
|
retValues[i] = f.read()
|
||||||
|
|
||||||
if completedFutures == len(retValues):
|
if completedFutures == len(retValues):
|
||||||
retFuture.complete(retValues)
|
retFuture.complete(retValues)
|
||||||
|
|
||||||
setCallback(i)
|
setCallback(i)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue