tasync_pragma.nim 438 B

12345678910111213141516171819202122232425262728
  1. discard """
  2. output: '''
  3. 0
  4. t
  5. '''
  6. """
  7. import asyncjs, macros
  8. macro f*(a: untyped): untyped =
  9. assert a.kind == nnkProcDef
  10. result = nnkProcDef.newTree(a.name, a[1], a[2], a.params, a.pragma, a[5], nnkStmtList.newTree())
  11. let call = quote:
  12. echo 0
  13. result.body.add(call)
  14. for child in a.body:
  15. result.body.add(child)
  16. #echo result.body.repr
  17. proc t* {.async, f.} =
  18. echo "t"
  19. proc t0* {.async.} =
  20. await t()
  21. discard t0()