Example usage for org.apache.commons.javaflow.extras ContinuableRunnable run

List of usage examples for org.apache.commons.javaflow.extras ContinuableRunnable run

Introduction

In this page you can find the example usage for org.apache.commons.javaflow.extras ContinuableRunnable run.

Prototype

@continuable
void run();

Source Link

Document

Run method re-declared as continuable

Usage

From source file:org.apache.commons.javaflow.examples.lambdas.LambdasExample.java

private @continuable void executeAll() {

    //  @Continuable method references and @Continuable SAM interfaces are supported
    ContinuableRunnable r1 = this::lambdaDemo;
    r1.run();

    ContinuableRunnable r2 = () -> {/*from  w  ww  . j  a v  a  2 s.  c  o  m*/
        System.out.println("ContinuableRunnable by arrow function -- before");
        Continuation.suspend(" ** ContinuableRunnable by arrow function");
        System.out.println("ContinuableRunnable by arrow function -- after");
    };
    r2.run();

    // Lambda reference MUST have annotated CallSite if SAM interface is not @continuable
    // Notice that we still MUST create right interface (ContinuableRunnable in this case)
    @ccs
    Runnable closure = exec(() -> {
        System.out.println("Plain Runnable Lambda by arrow function -- before");
        Continuation.suspend(" ** Plain Runnable Lambda by arrow function" + ref);
        System.out.println("Plain Runnable Lambda by arrow function -- after");
    });
    closure.run();

    // We can't use stream.forEach as is, but we can provide good enough helpers
    // See org.apache.commons.javaflow.examples.lambdas.ContinuableAdapters for
    // definition of "accept" & "forEach"
    List<String> listOfStrings = Arrays.asList("A", null, "B", null, "C");
    Continuations.forEach(listOfStrings.stream().filter(s -> s != null).map(s -> s + s),
            accept(this::yieldString1).andThen(this::yieldString2));

}