Open
Description
When trying to wait for the guard future I've encountered a wrong behaviour, IMHO. The idea is to wait some arbitrary future, which might be completed from some outer code not depending on guarded async code completed or not.
This code
import asyncdispatch
var guardfuture = newFuture[void]("test.guardfuture")
proc a() {.async.} =
await sleepAsync(1000)
proc b() {.async.} =
var af: auto = a()
await guardfuture
await af
proc fireGuard() =
guardfuture.complete()
proc testGuard() {.async.} =
await b()
proc stop() {.noconv.} =
fireGuard()
when isMainModule:
setControlCHook(stop)
waitFor testGuard()
quit(QuitSuccess)
should wait forever till ctrl+C pressed, but it fails just after proc a completes, with a message
/usr/local/Cellar/nim/1.2.0/nim/lib/pure/asyncdispatch.nim(1886) waitFor
/usr/local/Cellar/nim/1.2.0/nim/lib/pure/asyncdispatch.nim(1576) poll
/usr/local/Cellar/nim/1.2.0/nim/lib/pure/asyncdispatch.nim(1291) runOnce
Error: unhandled exception: No handles or timers registered in dispatcher. [ValueError]
but if I comment out awaiting the guardfuture in proc a, everything works without errors, but not as expected and quits just after a() completes.
If I press ctrl+c while timer is ticking, everything also works as a charm.
$ nim -v
Nim Compiler Version 1.2.0 [MacOSX: amd64]
The latest build from source has the same issue.
$ ./bin/nim -v
Nim Compiler Version 1.3.5 [MacOSX: amd64]