diff options
author | Konstantin Molchanov <Konstantin Molchanov> | 2016-06-01 00:54:49 +0400 |
---|---|---|
committer | Konstantin Molchanov <Konstantin Molchanov> | 2016-06-01 00:54:49 +0400 |
commit | a29f8df5bb76d24c9ac5d8ed8b8282968111cf4c (patch) | |
tree | 29b54a03d57fa4a2274950651e89145e188e4a25 | |
parent | 81c7be1b35da6a4f7a06b3f081a92b516ee34ee6 (diff) | |
download | Nim-a29f8df5bb76d24c9ac5d8ed8b8282968111cf4c.tar.gz |
stdlib: asyncdispatch: `all`: Tests now pass; import sequtils removed; Future[void] case optimized.
-rw-r--r-- | lib/pure/asyncdispatch.nim | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim index 50349b104..624836358 100644 --- a/lib/pure/asyncdispatch.nim +++ b/lib/pure/asyncdispatch.nim @@ -9,7 +9,7 @@ include "system/inclrtl" -import os, oids, tables, strutils, macros, times, heapqueue, sequtils +import os, oids, tables, strutils, macros, times, heapqueue import nativesockets, net, queues @@ -363,7 +363,23 @@ proc all*[T](futs: varargs[Future[T]]): auto = ## in the order they are passed. when T is void: - return foldl(futs, a and b) + var + retFuture = newFuture[void]("asyncdispatch.all") + completedFutures = 0 + + let totalFutures = len(futs) + + for i, fut in futs: + proc setCallback(i: int) = + fut.callback = proc(f: Future[T]) = + inc(completedFutures) + + if completedFutures == totalFutures: + retFuture.complete() + + setCallback(i) + + return retFuture else: var |