mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-08 12:54:22 +00:00
std/asyncjs allow transforming proc types (#21356)
* Add test case * Implement JS async transform for nnkProcTy
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user