-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how can i pass continuation proc as an argument? #323
Comments
Use Lines 62 to 81 in 0710578
|
not working if continuation postpones in event loop import pkg/cps
var wait: Continuation
proc noop(c: Continuation): Continuation {.cpsMagic.} =
wait = c
return nil
proc a(x: int): int {.cps: Continuation.} =
noop()
return x * 2
proc b(c: proc(x: int): int {.cps: Continuation.}) {.cps: Continuation.} =
var y = c.call(10)
echo c.recover(y)
b(whelp a)
discard trampoline wait
|
also is it possible to pass either a continuation or a regular function? something like that proc a(b: proc(x:int):int) {.cps: C}
proc a(b: proc(x:int):int {.cps: C}) {.cps: C} |
Try the |
Here's the updated form of your test, which prints import pkg/cps
var wait: Continuation
proc noop(c: Continuation): Continuation {.cpsMagic.} =
wait = c
return nil
proc a(x: int): int {.cps: Continuation.} =
noop()
return x * 2
type
A = proc (x: int): int {.cps: Continuation.}
proc b(c: A) {.cps: Continuation.} =
echo c(10)
b(whelp a)
discard trampoline wait |
Also, yes, it is possible to overload |
Not working with lambdas, I think #218 related import cps
proc a(b: proc() {.cps: Continuation.}) {.cps: Continuation.} =
b()
a(proc () {.cps: Continuation.} =
echo 1
) Error: Expected a node of kind nnkProcDef, got nnkLambda |
I want to pass cps proc to another proc to be called
a bit extended example why i want it
So its some function that creates new continuation which result i can await in other continuation
The text was updated successfully, but these errors were encountered: