mirror of
https://github.com/status-im/nim-eth.git
synced 2025-02-03 01:53:59 +00:00
wait for cancellation to be processed on timeout (#311)
This commit is contained in:
parent
bc8a8947fc
commit
114680453f
@ -1,5 +1,5 @@
|
|||||||
import
|
import
|
||||||
chronos, chronicles, chronicles/chronos_tools
|
chronos, chronicles/chronos_tools
|
||||||
|
|
||||||
export
|
export
|
||||||
chronos_tools
|
chronos_tools
|
||||||
@ -10,7 +10,10 @@ template awaitWithTimeout*[T](operation: Future[T],
|
|||||||
let f = operation
|
let f = operation
|
||||||
await f or deadline
|
await f or deadline
|
||||||
if not f.finished:
|
if not f.finished:
|
||||||
cancel f
|
# If we don't wait for for the cancellation here, it's possible that
|
||||||
|
# the "next" operation will run concurrently to this one, messing up
|
||||||
|
# the order of operations (since await/async is not fair)
|
||||||
|
await cancelAndWait(f)
|
||||||
onTimeout
|
onTimeout
|
||||||
else:
|
else:
|
||||||
f.read
|
f.read
|
||||||
@ -19,4 +22,3 @@ template awaitWithTimeout*[T](operation: Future[T],
|
|||||||
timeout: Duration,
|
timeout: Duration,
|
||||||
onTimeout: untyped): T =
|
onTimeout: untyped): T =
|
||||||
awaitWithTimeout(operation, sleepAsync(timeout), onTimeout)
|
awaitWithTimeout(operation, sleepAsync(timeout), onTimeout)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user