mirror of
https://github.com/status-im/nim-codex.git
synced 2025-01-09 10:32:11 +00:00
13bbf2b052
Give test more time to complete but do not increase sleep time more than necessary, by introducing waiting loop for test purposes.
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()
|