std/asyncjs allow transforming proc types (#21356)
* Add test case * Implement JS async transform for nnkProcTy
This commit is contained in:
parent
1d06c2b6cf
commit
cac49694c0
2 changed files with 14 additions and 1 deletions
|
|
@ -100,10 +100,18 @@ proc isFutureVoid(node: NimNode): bool =
|
||||||
node[1].kind == nnkIdent and $node[1] == "void"
|
node[1].kind == nnkIdent and $node[1] == "void"
|
||||||
|
|
||||||
proc generateJsasync(arg: NimNode): NimNode =
|
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." &
|
error("Cannot transform this node kind into an async proc." &
|
||||||
" proc/method definition or lambda node expected.")
|
" 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
|
result = arg
|
||||||
var isVoid = false
|
var isVoid = false
|
||||||
let jsResolve = ident("jsResolve")
|
let jsResolve = ident("jsResolve")
|
||||||
|
|
|
||||||
|
|
@ -94,4 +94,9 @@ proc main() {.async.} =
|
||||||
doAssert "foobar: 7" in $reason.message
|
doAssert "foobar: 7" in $reason.message
|
||||||
echo "done" # justified here to make sure we're running this, since it's inside `async`
|
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()
|
discard main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue