Skip to content

Instantly share code, notes, and snippets.

@reevik
Last active March 11, 2019 10:56
Show Gist options
  • Save reevik/ca778c60921caad6d7999aa7da6a512a to your computer and use it in GitHub Desktop.
Save reevik/ca778c60921caad6d7999aa7da6a512a to your computer and use it in GitHub Desktop.
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