mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-03 14:03:10 +00:00
14 lines
339 B
Nim
14 lines
339 B
Nim
|
|
import pkg/chronos
|
||
|
|
|
||
|
|
template eventually*(condition: untyped, timeout = 5.seconds): bool =
|
||
|
|
proc loop: Future[bool] {.async.} =
|
||
|
|
let start = Moment.now()
|
||
|
|
while true:
|
||
|
|
if condition:
|
||
|
|
return true
|
||
|
|
if Moment.now() > (start + timeout):
|
||
|
|
return false
|
||
|
|
else:
|
||
|
|
await sleepAsync(1.millis)
|
||
|
|
await loop()
|