I don't understand why this example don't work. Is the body of the template should not simply be inlined at compile time?
I think it's because async proc is transformed into iterator so you can't return immediately. This works
import asyncdispatch
template test: untyped =
result = true
proc main(): Future[bool] {.async.} =
test()
doAssert waitFor main()
Thank you, I think I can work with this.
I think it's because async proc is transformed into iterator so you can't return immediately
If this is the reason, then this code shouldn't work, but it does
import asyncdispatch
proc main(): Future[bool] {.async.} =
return true
doAssert waitFor main()
For some reason, the error is just wrong. Simply putting a discard statement in front of your bottom expression works:
import asyncdispatch
template test: untyped =
return true
proc main(): Future[bool] {.async.} =
test
discard waitFor main()