tasyncdiscard.nim 424 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. discard """
  2. output: '''
  3. 1
  4. 2
  5. 3
  6. 4
  7. 1
  8. 2
  9. 1
  10. 6
  11. '''
  12. """
  13. import asyncdispatch, asyncnet
  14. proc main {.async.} =
  15. proc f: Future[int] {.async.} =
  16. discard
  17. echo 1
  18. discard
  19. result = 2
  20. discard
  21. let x = await f()
  22. echo x
  23. echo 3
  24. proc g: Future[int] {.async.} =
  25. discard
  26. echo 4
  27. discard
  28. result = 6
  29. discard
  30. echo await f()
  31. discard await f()
  32. discard await g()
  33. echo 6
  34. waitFor(main())