From 34b81961d394bff35ac24916fe1ce22d3efd0599 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Sun, 16 Aug 2020 01:34:42 +0300 Subject: [PATCH] Revert "asyncCheck(): don't raise exception on cancellation (#121)" This reverts commit baf33f04eaac481251ca306258ca5877e7a45a46. This change hides exceptions that should be handled explicitly - asyncCheck is a debugging tool that should only be used in exception-free situations (indeed, to fail when the operation unexpectedly raises). There is no rough consensus behind this change. --- chronos/asyncfutures2.nim | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/chronos/asyncfutures2.nim b/chronos/asyncfutures2.nim index 8f7f8b6504..b55b0416f8 100644 --- a/chronos/asyncfutures2.nim +++ b/chronos/asyncfutures2.nim @@ -531,11 +531,13 @@ proc mget*[T](future: FutureVar[T]): var T = result = Future[T](future).value proc asyncCheck*[T](future: Future[T]) = - ## Sets a callback on ``future`` which raises an exception in ``poll()`` if the - ## future failed. + ## Sets a callback on ``future`` which raises an exception if the future + ## finished with an error. + ## + ## This should be used instead of ``discard`` to discard void futures. doAssert(not isNil(future), "Future is nil") proc cb(data: pointer) = - if future.failed(): + if future.failed() or future.cancelled(): when defined(chronosStackTrace): injectStacktrace(future) raise future.error