summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lib/js/asyncjs.nim10
-rw-r--r--tests/js/tasyncjs.nim5
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/js/asyncjs.nim b/lib/js/asyncjs.nim
index 364f7a21a..8e2f85156 100644
--- a/lib/js/asyncjs.nim
+++ b/lib/js/asyncjs.nim
@@ -100,10 +100,18 @@ proc isFutureVoid(node: NimNode): bool =
            node[1].kind == nnkIdent and $node[1] == "void"
 
 proc generateJsasync(arg: NimNode): NimNode =
-  if arg.kind notin {nnkProcDef, nnkLambda, nnkMethodDef, nnkDo}:
+  if arg.kind notin {nnkProcDef, nnkLambda, nnkMethodDef, nnkDo, nnkProcTy}:
       error("Cannot transform this node kind into an async proc." &
             " proc/method definition or lambda node expected.")
 
+  # Transform type X = proc (): something {.async.}
+  # into      type X = proc (): Future[something]
+  if arg.kind == nnkProcTy:
+    result = arg
+    if arg[0][0].kind == nnkEmpty:
+      result[0][0] = quote do: Future[void]
+    return result
+
   result = arg
   var isVoid = false
   let jsResolve = ident("jsResolve")
diff --git a/tests/js/tasyncjs.nim b/tests/js/tasyncjs.nim
index 00753a16c..3de143643 100644
--- a/tests/js/tasyncjs.nim
+++ b/tests/js/tasyncjs.nim
@@ -94,4 +94,9 @@ proc main() {.async.} =
     doAssert "foobar: 7" in $reason.message
   echo "done" # justified here to make sure we're running this, since it's inside `async`
 
+block asyncPragmaInType:
+  type Handler = proc () {.async.}
+  proc foo() {.async.} = discard
+  var x: Handler = foo
+
 discard main()