summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorKonstantin Molchanov <kmolchanov@machinezone.com>2016-05-31 14:56:45 +0400
committerKonstantin Molchanov <kmolchanov@machinezone.com>2016-05-31 14:56:45 +0400
commit5a007a84fc8350a3a43ddc712c7a59a9ab2dce79 (patch)
tree33ed1d4de3299ebd87124fc0dfd3957aa4b9af89 /lib
parentfb9fa5f6a385d1861885b0481573e7dc97191d9f (diff)
downloadNim-5a007a84fc8350a3a43ddc712c7a59a9ab2dce79.tar.gz
Stdlib: asyncdispatch: `all` proc: Fix incorect counter value issue.
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/asyncdispatch.nim13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim
index de86cd5ef..53c78d929 100644
--- a/lib/pure/asyncdispatch.nim
+++ b/lib/pure/asyncdispatch.nim
@@ -368,12 +368,15 @@ proc all*[A](futs: openarray[Future[A]]): Future[seq[A]] =
     completedFutures = 0
 
   for i, fut in futs:
-    fut.callback = proc(f: Future[A]) =
-      retValues[i] = f.read()
-      inc(completedFutures)
+    proc setCallback(i: int) =
+      fut.callback = proc(f: Future[A]) =
+        retValues[i] = f.read()
+        inc(completedFutures)
 
-      if completedFutures == len(futs):
-        retFuture.complete(retValues)
+        if completedFutures == len(retValues):
+          retFuture.complete(retValues)
+
+    setCallback(i)
 
   return retFuture