Fix mock clock

This commit is contained in:
Arnaud 2025-10-02 11:33:33 +02:00
parent 07b442cea9
commit 6fc5cd2bf4
No known key found for this signature in database
GPG Key ID: B8FBC178F10CA7AE

View File

@ -33,11 +33,16 @@ proc advance*(clock: MockClock, seconds: int64) =
method now*(clock: MockClock): SecondsSince1970 =
clock.time
method waitUntil*(clock: MockClock, time: SecondsSince1970) {.async.} =
if time > clock.now():
let future = newFuture[void]()
clock.waiting.add(Waiting(until: time, future: future))
await future
method waitUntil*(
clock: MockClock, time: SecondsSince1970
) {.async: (raises: [CancelledError]).} =
try:
if time > clock.now():
let future = newFuture[void]()
clock.waiting.add(Waiting(until: time, future: future))
await future
except Exception as e:
discard
proc isWaiting*(clock: MockClock): bool =
clock.waiting.len > 0