* complete future only once in `or` Analogous to `and`. Credits to @k0zmo for proposing the solution. * add test
This commit is contained in:
parent
8d850f7a69
commit
964b5dac7c
2 changed files with 36 additions and 2 deletions
|
|
@ -375,8 +375,9 @@ proc `or`*[T, Y](fut1: Future[T], fut2: Future[Y]): Future[void] =
|
|||
## complete.
|
||||
var retFuture = newFuture[void]("asyncdispatch.`or`")
|
||||
proc cb[X](fut: Future[X]) =
|
||||
if fut.failed: retFuture.fail(fut.error)
|
||||
if not retFuture.finished: retFuture.complete()
|
||||
if not retFuture.finished:
|
||||
if fut.failed: retFuture.fail(fut.error)
|
||||
else: retFuture.complete()
|
||||
fut1.callback = cb[T]
|
||||
fut2.callback = cb[Y]
|
||||
return retFuture
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue