From b87ef6553201c73e24b1b53641cc18abe17d6e9b Mon Sep 17 00:00:00 2001 From: Mathias Stearn Date: Fri, 8 Dec 2017 19:55:04 -0500 Subject: [PATCH] Use addCallback rather than callback= in asyncfutures.all() (#6850) * Use addCallback rather than callback= in asyncfutures.all() Addresses part of #6849 * Stop using do notation for #6849 * Update example style --- lib/pure/asyncdispatch.nim | 5 +++-- lib/pure/asyncfutures.nim | 4 ++-- tests/async/tasyncall.nim | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim index 4c96aa6148..a71d30ab9f 100644 --- a/lib/pure/asyncdispatch.nim +++ b/lib/pure/asyncdispatch.nim @@ -59,9 +59,10 @@ export asyncfutures, asyncstreams ## ## .. code-block::nim ## var future = socket.recv(100) -## future.callback = +## future.addCallback( ## proc () = ## echo(future.read) +## ) ## ## All asynchronous functions returning a ``Future`` will not block. They ## will not however return immediately. An asynchronous function will have @@ -1611,4 +1612,4 @@ proc waitFor*[T](fut: Future[T]): T = fut.read -{.deprecated: [setEvent: trigger].} \ No newline at end of file +{.deprecated: [setEvent: trigger].} diff --git a/lib/pure/asyncfutures.nim b/lib/pure/asyncfutures.nim index bebd196114..4bd3227a11 100644 --- a/lib/pure/asyncfutures.nim +++ b/lib/pure/asyncfutures.nim @@ -333,7 +333,7 @@ proc all*[T](futs: varargs[Future[T]]): auto = let totalFutures = len(futs) for fut in futs: - fut.callback = proc(f: Future[T]) = + fut.addCallback proc (f: Future[T]) = inc(completedFutures) if not retFuture.finished: if f.failed: @@ -355,7 +355,7 @@ proc all*[T](futs: varargs[Future[T]]): auto = for i, fut in futs: proc setCallback(i: int) = - fut.callback = proc(f: Future[T]) = + fut.addCallback proc (f: Future[T]) = inc(completedFutures) if not retFuture.finished: if f.failed: diff --git a/tests/async/tasyncall.nim b/tests/async/tasyncall.nim index a3926eabdd..775dd0c6f0 100644 --- a/tests/async/tasyncall.nim +++ b/tests/async/tasyncall.nim @@ -40,6 +40,16 @@ proc testVarargs(x, y, z: int): seq[int] = result = waitFor all(a, b, c) +proc testWithDupes() = + var + tasks = newSeq[Future[void]](taskCount) + fut = futureWithoutValue() + + for i in 0..