mirror of https://github.com/status-im/nim-eth.git
Add a helper from NBC
This commit is contained in:
parent
964a380191
commit
5c6d8ccb36
|
@ -18,3 +18,20 @@ template traceAwaitErrors*(fut: FutureBase) =
|
|||
yield f
|
||||
if not f.error.isNil:
|
||||
catchOrQuit f.error[]
|
||||
|
||||
template awaitWithTimeout*[T](operation: Future[T],
|
||||
deadline: Future[void],
|
||||
onTimeout: untyped): T =
|
||||
let f = operation
|
||||
await f or deadline
|
||||
if not f.finished:
|
||||
cancel f
|
||||
onTimeout
|
||||
else:
|
||||
f.read
|
||||
|
||||
template awaitWithTimeout*[T](operation: Future[T],
|
||||
timeout: Duration,
|
||||
onTimeout: untyped): T =
|
||||
awaitWithTimeout(operation, sleepAsync(timeout), onTimeout)
|
||||
|
||||
|
|
Loading…
Reference in New Issue