Hi,
I've got a problem when using the dirty pragma within an async context. I want to "inject" a templates body into a procedure for less typing. If there's an error, the template should handle this error and return within the handleJoin proc.
Could this be an unsolveable issue, when using async? As far as I know the async pragma is not allowed with templates.
Example:
# [...]
proc responseError(req: Request, error: MatchError): Future[void] {.async.} =
await req.respond(Http400, $error)
template handleError(error: untyped): untyped {.dirty.} =
if error.isError:
case req.reqMethod
of HttpGet:
await req.responseError(error)
else:
raise newException(ValueError, "Currently only GET is supported!")
return # <-- This should prevent executing code after the handleError call
proc handleJoin(req: Request): Future[void] {.async.} =
var (error, match) = getMatch()
handleError(error)
# Some other code which should not be executed when there's an error.
# [...]
It fails with:
Error: Await only available within .async