tasync_gcsafe.nim 774 B

12345678910111213141516171819202122232425262728293031323334353637
  1. discard """
  2. cmd: "nim c --threads:on $file"
  3. output: '''
  4. 1
  5. 2
  6. 3
  7. '''
  8. """
  9. doAssert compileOption("threads"), "this test will not do anything useful without --threads:on"
  10. import asyncdispatch
  11. var globalDummy: ref int
  12. proc gcUnsafeProc() =
  13. if not globalDummy.isNil:
  14. echo globalDummy[]
  15. echo "1"
  16. proc gcSafeAsyncProcWithNoAnnotation() {.async.} =
  17. echo "2"
  18. proc gcSafeAsyncProcWithAnnotation() {.gcsafe, async.} =
  19. echo "3"
  20. proc gcUnsafeAsyncProc() {.async.} =
  21. # We should be able to call gcUnsafe
  22. gcUnsafeProc()
  23. # We should be able to call async implicitly gcsafe
  24. await gcSafeAsyncProcWithNoAnnotation()
  25. # We should be able to call async explicitly gcsafe
  26. await gcSafeAsyncProcWithAnnotation()
  27. waitFor gcUnsafeAsyncProc()