tasyncjs_pragma.nim 469 B

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