Skip to content
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

Can't use await in templates #12743

Closed
dawkot opened this issue Nov 26, 2019 · 4 comments
Closed

Can't use await in templates #12743

dawkot opened this issue Nov 26, 2019 · 4 comments

Comments

@dawkot
Copy link

dawkot commented Nov 26, 2019

Example

import asyncdispatch

template templ = await sleepAsync 0

proc prc {.async.} = templ

or

import asyncdispatch

template templ {.dirty.} = await sleepAsync 0

proc prc {.async.} = templ

Current Output

/usercode/in.nim(5, 12) template/generic instantiation of `async` from here
/playground/nim/lib/pure/asyncmacro.nim(448, 10) Error: Await only available within .async

Expected Output

No errors

Additional Information

$ nim -v
Nim Compiler Version 1.0.2
@zedeus
Copy link
Contributor

zedeus commented Nov 26, 2019

Known issue, #3885 says to use yield instead. Also #12085 but it's blocked by #12372

@dawkot
Copy link
Author

dawkot commented Apr 14, 2020

Funny, it works on JS backend

import asyncjs, dom

template t =
  await newPromise do(resolve: proc()):
    discard setTimeout(resolve, 3000)

proc p {.async.} =
  t
  echo "Hello"

discard p()

@alehander92
Copy link
Contributor

i should fix this this week , sorry

@metagn
Copy link
Collaborator

metagn commented Apr 30, 2020

This was fixed by #12085 and a test was added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants