diff --git a/chronos/asyncfutures2.nim b/chronos/asyncfutures2.nim index 2de139c..97ac1f7 100644 --- a/chronos/asyncfutures2.nim +++ b/chronos/asyncfutures2.nim @@ -469,12 +469,12 @@ proc asyncCheck*[T](future: Future[T]) = proc asyncDiscard*[T](future: Future[T]) = discard ## This is async workaround for discard ``Future[T]``. -proc `and`*[T, Y](fut1: Future[T], fut2: Future[Y]): Future[void] = +proc `and`*[T, Y](fut1: Future[T], fut2: Future[Y]): Future[void] {. + deprecated: "Use allFutures[T](varargs[Future[T]])".} = ## Returns a future which will complete once both ``fut1`` and ``fut2`` ## complete. ## - ## TODO: In case when `fut1` or `fut2` got cancelled, what result Future[void] - ## should return? + ## If cancelled, ``fut1`` and ``fut2`` futures WILL NOT BE cancelled. var retFuture = newFuture[void]("chronos.`and`") proc cb(data: pointer) = if not(retFuture.finished()): @@ -493,20 +493,20 @@ proc `and`*[T, Y](fut1: Future[T], fut2: Future[Y]): Future[void] = fut2.callback = cb proc cancel(udata: pointer) {.gcsafe.} = + # On cancel we remove all our callbacks only. if not(retFuture.finished()): fut1.removeCallback(cb) fut2.removeCallback(cb) - if not(fut1.finished()): - fut1.cancel() - if not(fut2.finished()): - fut2.cancel() retFuture.cancelCallback = cancel return retFuture -proc `or`*[T, Y](fut1: Future[T], fut2: Future[Y]): Future[void] = +proc `or`*[T, Y](fut1: Future[T], fut2: Future[Y]): Future[void] {. + deprecated: "Use one[T](varargs[Future[T]])".} = ## Returns a future which will complete once either ``fut1`` or ``fut2`` ## complete. + ## + ## If cancelled, ``fut1`` and ``fut2`` futures WILL NOT BE cancelled. var retFuture = newFuture[void]("chronos.`or`") proc cb(udata: pointer) {.gcsafe.} = if not(retFuture.finished()): @@ -521,18 +521,16 @@ proc `or`*[T, Y](fut1: Future[T], fut2: Future[Y]): Future[void] = fut2.callback = cb proc cancel(udata: pointer) {.gcsafe.} = + # On cancel we remove all our callbacks only. if not(retFuture.finished()): fut1.removeCallback(cb) fut2.removeCallback(cb) - if not(fut1.finished()): - fut1.cancel() - if not(fut2.finished()): - fut2.cancel() retFuture.cancelCallback = cancel return retFuture -proc all*[T](futs: varargs[Future[T]]): auto = +proc all*[T](futs: varargs[Future[T]]): auto {. + deprecated: "Use allFutures(varargs[Future[T]])".} = ## Returns a future which will complete once all futures in ``futs`` complete. ## If the argument is empty, the returned future completes immediately. ## @@ -568,20 +566,12 @@ proc all*[T](futs: varargs[Future[T]]): auto = if not(retFuture.failed()): retFuture.complete() - proc cancel(udata: pointer) {.gcsafe.} = - if not(retFuture.finished()): - for i in 0..