-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why isn’t chronosInternalRetFuture
gensymmed?
#368
Comments
Because |
But you can inject a separate |
Do you have an isolated repro fot this? |
With ease. Here you are: import std/macros
when not declared assert:
import std/assertions
when defined useChronos:
import chronos/asyncloop
else:
import std/asyncdispatch
macro wrapWithSubproc(body) =
body.expectKind nnkStmtList
body[0].expectKind nnkStmtList
let n = body[0].len - 1
let ret = body[0][n]
ret.expectKind nnkReturnStmt
body[0].del n # Detach from the body.
result = quote:
proc inner {.async, genSym.} = `body`
await inner()
`ret` # Reattach here.
echo treeRepr result
proc outer: Future[string] {.async.} =
wrapWithSubproc:
return "ok"
doAssert waitFor(outer()) == "ok"
N.B. Of course, in my library, I do not assume that return-related code has any particular shape. I traverse it and search for my own annotations I put there before. |
nim-chronos/chronos/asyncmacro2.nim
Lines 126 to 133 in f3b77d8
If you take the body of a procedure after it is processed by
.async
, put it into a new procedure, and apply.async
to it,chronosInternalRetFuture
will refer to the wrong variable.std/asyncmacro
does not suffer from this.P.S. If you are curious, I’m trying to make my asyncIters library work with Chronos.
The text was updated successfully, but these errors were encountered: