summary refs log tree commit diff stats
path: root/tests/async/tasync_gcsafe.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/async/tasync_gcsafe.nim')
-rw-r--r--tests/async/tasync_gcsafe.nim36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/async/tasync_gcsafe.nim b/tests/async/tasync_gcsafe.nim
new file mode 100644
index 000000000..bc0eb4271
--- /dev/null
+++ b/tests/async/tasync_gcsafe.nim
@@ -0,0 +1,36 @@
+discard """
+  cmd: "nim c --threads:on $file"
+  output: '''
+1
+2
+3
+'''
+"""
+
+doAssert compileOption("threads"), "this test will not do anything useful without --threads:on"
+
+import asyncdispatch
+
+var globalDummy: ref int
+proc gcUnsafeProc() =
+    if not globalDummy.isNil:
+        echo globalDummy[]
+    echo "1"
+
+proc gcSafeAsyncProcWithNoAnnotation() {.async.} =
+    echo "2"
+
+proc gcSafeAsyncProcWithAnnotation() {.gcsafe, async.} =
+    echo "3"
+
+proc gcUnsafeAsyncProc() {.async.} =
+    # We should be able to call gcUnsafe
+    gcUnsafeProc()
+
+    # We should be able to call async implicitly gcsafe
+    await gcSafeAsyncProcWithNoAnnotation()
+
+    # We should be able to call async explicitly gcsafe
+    await gcSafeAsyncProcWithAnnotation()
+
+waitFor gcUnsafeAsyncProc()