asynctools
asynctools copied to clipboard
Async task not waiting for event once fired
The use case is waiting for some event until some condition is met. If the condition is not met, it should go back to wait. In the following code the condition is never met (the while true simulates this), but the async proc does not wait again (or it waits but it's immediately awaken)
block:
var event = newAsyncEv()
proc testEvent(n: int, ev: AsyncEv) {.async.} =
while true:
await ev.wait()
debugEcho n
event.clear()
asyncCheck testEvent(0, event)
asyncCheck testEvent(1, event)
event.fire()
event.clear()
waitFor sleepAsync(10_000)
Current output:
0
1
0
1
0
1
[so on]
Expected:
0
1