2019-03-28 12:52:31 +02:00
|
|
|
import
|
2020-08-15 00:31:09 +03:00
|
|
|
chronos, chronicles, chronicles/chronos_tools
|
2019-04-05 10:13:22 +02:00
|
|
|
|
2020-08-15 00:31:09 +03:00
|
|
|
export
|
|
|
|
chronos_tools
|
2020-06-17 19:14:05 +03:00
|
|
|
|
|
|
|
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)
|
|
|
|
|