summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKonstantin Molchanov <Konstantin Molchanov>2016-06-01 00:54:49 +0400
committerKonstantin Molchanov <Konstantin Molchanov>2016-06-01 00:54:49 +0400
commita29f8df5bb76d24c9ac5d8ed8b8282968111cf4c (patch)
tree29b54a03d57fa4a2274950651e89145e188e4a25
parent81c7be1b35da6a4f7a06b3f081a92b516ee34ee6 (diff)
downloadNim-a29f8df5bb76d24c9ac5d8ed8b8282968111cf4c.tar.gz
stdlib: asyncdispatch: `all`: Tests now pass; import sequtils removed; Future[void] case optimized.
-rw-r--r--lib/pure/asyncdispatch.nim20
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
165' href='#n165'>165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208