For when Result support will be more tightly integrated into chronos, it would be nice to have a catch that takes into account, and propagates, CancelledError, eg:
template catchAsync*(body: typed): Result[type(body), ref CatchableError] =
## Catch exceptions for `body` containing `await` and store them in the
## Result, propagating cancellations.
##
## ```
## let r = catchAsync: await someAsyncFuncThatMayRaise()
## ```
type R = Result[type(body), ref CatchableError]
try:
when type(body) is void:
body
R.ok()
else:
R.ok(body)
except CancelledError as eCancelled:
raise eCancelled
except CatchableError as eResultPrivate:
R.err(eResultPrivate)
For when Result support will be more tightly integrated into chronos, it would be nice to have a
catchthat takes into account, and propagates,CancelledError, eg: