Last active
March 11, 2019 10:56
-
-
Save reevik/ca778c60921caad6d7999aa7da6a512a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.ryos.demos.continuations; | |
import static java.lang.System.out; | |
import java.util.Arrays; | |
import java.util.List; | |
public class ContinuationDemo { | |
public static void main(String[] args) { | |
var scope = new ContinuationScope("my-scope"); | |
var cont = new Continuation(scope, () -> { | |
final List<String> letters = Arrays.asList("a", "b", "c"); | |
for (var letter : letters) { | |
out.println("Your letter is: " + letter); | |
out.println("In Cont the thread is: " + Thread.currentThread().getName()); | |
out.println("Yielding ..."); | |
Continuation.yield(scope); | |
} | |
}); | |
while (!cont.isDone()) { | |
cont.run(); | |
out.println("After run, the thread is " + Thread.currentThread().getName()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment