<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<div dir="auto">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:<br></div><div dir="auto"><br></div><ol><li dir="auto">Is it possible to pass in arguments like Lua's coroutine[1][2]?<br></li><li dir="auto">Is it possible to yield/ return some values like Lua's coroutine[1][2]?<br></li><li dir="auto">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? <br></li><li dir="auto">Is it possible to capture Continuation's snapshot for later use?<br></li></ol><div dir="auto">Many thanks<br></div><div dir="auto"><br></div><div dir="auto">import jdk.internal.vm.ContinuationScope;<br></div><div dir="auto">import jdk.internal.vm.Continuation;<br></div><div dir="auto"><br></div><div dir="auto">public class C {<br></div><div dir="auto"><br></div><div dir="auto"> public static void main(String[] args) {<br></div><div dir="auto"> var scope = new ContinuationScope("hello");<br></div><div dir="auto"> var yield = Continuation::yield;<br></div><div dir="auto"> var continuation = new Continuation(scope, () -> {<br></div><div dir="auto"> System.out.println("C1");<br></div><div dir="auto"> Continuation.yield(scope);<br></div><div dir="auto"> System.out.println("C2");<br></div><div dir="auto"> Continuation.yield(scope);<br></div><div dir="auto"> System.out.println("C3");<br></div><div dir="auto"> });<br></div><div dir="auto"> System.out.println("start");<br></div><div dir="auto"> continuation.run();<br></div><div dir="auto"> System.out.println("came back");<br></div><div dir="auto"> continuation.run();<br></div><div dir="auto"> System.out.println("back again");<br></div><div dir="auto"> continuation.run();<br></div><div dir="auto"> System.out.println("back again again");<br></div><div dir="auto"> }<br></div><div dir="auto">}<br></div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">[1]. <a href="https://stackoverflow.com/questions/38069751/confusion-about-lua-corountines-resume-and-yield-function/38075905#38075905" rel="noopener noreferrer" target="_blank">https://stackoverflow.com/questions/38069751/confusion-about-lua-corountines-resume-and-yield-function/38075905#38075905</a><br></div><div dir="auto"><br></div><div dir="auto">[2]. <a href="https://www.lua.org/pil/9.1.html" rel="noopener noreferrer" target="_blank">https://www.lua.org/pil/9.1.html</a><br></div> </body>
</html>