2019-03-28 10:52:31 +00:00
|
|
|
import
|
2019-04-05 08:13:22 +00:00
|
|
|
chronos/[asyncfutures2, asyncloop], chronicles
|
|
|
|
|
|
|
|
proc catchOrQuit(error: Exception) =
|
|
|
|
if error of CatchableError:
|
|
|
|
trace "Async operation ended with a recoverable error", err = error.msg
|
|
|
|
else:
|
|
|
|
fatal "Fatal exception reached", err = error.msg
|
|
|
|
quit 1
|
2019-03-28 10:52:31 +00:00
|
|
|
|
|
|
|
proc traceAsyncErrors*(fut: FutureBase) =
|
|
|
|
fut.addCallback do (arg: pointer):
|
|
|
|
if not fut.error.isNil:
|
2019-04-05 08:13:22 +00:00
|
|
|
catchOrQuit fut.error[]
|
2019-03-28 10:52:31 +00:00
|
|
|
|
2019-04-05 08:13:22 +00:00
|
|
|
template traceAwaitErrors*(fut: FutureBase) =
|
|
|
|
let f = fut
|
|
|
|
yield f
|
|
|
|
if not f.error.isNil:
|
|
|
|
catchOrQuit f.error[]
|