diff options
author | Ruslan Mustakov <r.mustakov@gmail.com> | 2016-11-02 20:04:08 +0700 |
---|---|---|
committer | Ruslan Mustakov <r.mustakov@gmail.com> | 2016-11-03 10:50:43 +0700 |
commit | f2bded180f1c5fcb0994bc7d86d6221cd9ba6504 (patch) | |
tree | e43597fdb6e27e1c3bbdfbac655ea97e1b77f594 /lib | |
parent | 5842f7d0d250eab6e5d3a4c0fb75f5bdc4a86d53 (diff) | |
download | Nim-f2bded180f1c5fcb0994bc7d86d6221cd9ba6504.tar.gz |
async all() now immediately completes if arg is empty
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/includes/asyncfutures.nim | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/pure/includes/asyncfutures.nim b/lib/pure/includes/asyncfutures.nim index d78464a91..dfcfa37a0 100644 --- a/lib/pure/includes/asyncfutures.nim +++ b/lib/pure/includes/asyncfutures.nim @@ -246,6 +246,7 @@ proc `or`*[T, Y](fut1: Future[T], fut2: Future[Y]): Future[void] = proc all*[T](futs: varargs[Future[T]]): auto = ## Returns a future which will complete once ## all futures in ``futs`` complete. + ## If the argument is empty, the returned future completes immediately. ## ## If the awaited futures are not ``Future[void]``, the returned future ## will hold the values of all awaited futures in a sequence. @@ -270,6 +271,9 @@ proc all*[T](futs: varargs[Future[T]]): auto = if completedFutures == totalFutures: retFuture.complete() + if totalFutures == 0: + retFuture.complete() + return retFuture else: @@ -292,4 +296,7 @@ proc all*[T](futs: varargs[Future[T]]): auto = setCallback(i) + if retValues.len == 0: + retFuture.complete(retValues) + return retFuture |