Coroutine questions
common1945 at tutanota.com
common1945 at tutanota.com
Tue Mar 18 16:39:08 UTC 2025
I am doing some experiments that will make use of loom's Continuation with jdk22+. I know that I can achieve java Continuation effect with following code. However, I have a few questions:
Is it possible to pass in arguments like Lua's coroutine[1][2]?
Is it possible to yield/ return some values like Lua's coroutine[1][2]?
Does the way to communicate between the Continuation block i.e. Runnable and outside Runnable merely be able to achieved by embedding e.g. BlockingQueue inside the Runnable code block?
Is it possible to capture Continuation's snapshot for later use?
Many thanks
import jdk.internal.vm.ContinuationScope;
import jdk.internal.vm.Continuation;
public class C {
public static void main(String[] args) {
var scope = new ContinuationScope("hello");
var yield = Continuation::yield;
var continuation = new Continuation(scope, () -> {
System.out.println("C1");
Continuation.yield(scope);
System.out.println("C2");
Continuation.yield(scope);
System.out.println("C3");
});
System.out.println("start");
continuation.run();
System.out.println("came back");
continuation.run();
System.out.println("back again");
continuation.run();
System.out.println("back again again");
}
}
[1]. https://stackoverflow.com/questions/38069751/confusion-about-lua-corountines-resume-and-yield-function/38075905#38075905
[2]. https://www.lua.org/pil/9.1.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20250318/a526ec96/attachment.htm>
More information about the loom-dev
mailing list