Fix asyncCheck.
This commit is contained in:
parent
c102deac9d
commit
d949710d8d
|
@ -358,25 +358,17 @@ proc failed*(future: FutureBase): bool =
|
||||||
## Determines whether ``future`` completed with an error.
|
## Determines whether ``future`` completed with an error.
|
||||||
return future.error != nil
|
return future.error != nil
|
||||||
|
|
||||||
proc asyncCheckProxy[T](udata: pointer) =
|
|
||||||
var future = cast[Future[T]](udata)
|
|
||||||
if future.failed:
|
|
||||||
injectStacktrace(future)
|
|
||||||
raise future.error
|
|
||||||
|
|
||||||
proc asyncCheck*[T](future: Future[T]) =
|
proc asyncCheck*[T](future: Future[T]) =
|
||||||
## Sets a callback on ``future`` which raises an exception if the future
|
## Sets a callback on ``future`` which raises an exception if the future
|
||||||
## finished with an error.
|
## finished with an error.
|
||||||
##
|
##
|
||||||
## This should be used instead of ``discard`` to discard void futures.
|
## This should be used instead of ``discard`` to discard void futures.
|
||||||
assert(not future.isNil, "Future is nil")
|
assert(not future.isNil, "Future is nil")
|
||||||
# ZAH: This should probably add a callback instead of replacing all call-backs.
|
proc cb(data: pointer) =
|
||||||
# Perhaps a new API can be introduced to avoid the breaking change.
|
if future.failed:
|
||||||
future.callback = asyncCheckProxy[T]
|
injectStacktrace(future)
|
||||||
# proc (udata: pointer) =
|
raise future.error
|
||||||
# if future.failed:
|
future.callback = cb
|
||||||
# injectStacktrace(future)
|
|
||||||
# raise future.error
|
|
||||||
|
|
||||||
# ZAH: The return type here could be a Future[(T, Y)]
|
# ZAH: The return type here could be a Future[(T, Y)]
|
||||||
proc `and`*[T, Y](fut1: Future[T], fut2: Future[Y]): Future[void] =
|
proc `and`*[T, Y](fut1: Future[T], fut2: Future[Y]): Future[void] =
|
||||||
|
|
Loading…
Reference in New Issue