tasync.nim 409 B

12345678910111213141516171819202122232425262728293031323334
  1. discard """
  2. output: '''
  3. x
  4. e
  5. '''
  6. """
  7. import asyncjs
  8. # demonstrate forward definition
  9. # for js
  10. proc y(e: int): Future[string] {.async.}
  11. proc e: int {.discardable.} =
  12. echo "e"
  13. return 2
  14. proc x(e: int): Future[void] {.async.} =
  15. var s = await y(e)
  16. if e > 2:
  17. return
  18. echo s
  19. e()
  20. proc y(e: int): Future[string] {.async.} =
  21. if e > 0:
  22. return await y(0)
  23. else:
  24. return "x"
  25. discard x(2)