Example usage for org.apache.commons.javaflow.api Continuation suspend

List of usage examples for org.apache.commons.javaflow.api Continuation suspend

Introduction

In this page you can find the example usage for org.apache.commons.javaflow.api Continuation suspend.

Prototype

public static Object suspend(final Object value) 

Source Link

Document

Stops the running continuation.

Usage

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

@continuable
void yieldString2(String s) {
    System.out.println("Before yield II");
    Continuation.suspend("yield II " + s);
    System.out.println("After yield II");
}

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

public static void main(final String[] argv) throws Exception {

    Continuation cc = Continuations.start(() -> {
        for (int i = 1; i <= 5; i++) {
            System.out.println("Exe before suspend");
            Continuation.suspend(i);
            System.out.println("Exe after suspend");
        }/*w ww .j a v a  2s .  c  o  m*/
    });

    for (; null != cc; cc = cc.resume()) {
        System.out.println("Interrupted " + cc.value());
    }

    System.out.println("===");
}

From source file:org.apache.commons.javaflow.examples.nested.ExecutionInner.java

@Override
public @continuable void run() {
    for (char c = 'A'; c < 'E'; c++) {
        StringBuilder v = new StringBuilder();
        v.append(c).append(i);//from   ww  w.j  a  va2s  .c o  m
        System.out.println("\tInner " + v);
        Continuation.suspend(v);
    }
}

From source file:org.apache.commons.javaflow.examples.nested.ExecutionOuter.java

@Override
public @continuable void run() {
    for (int i = 1; i <= 5; i++) {
        System.out.println("Execution " + i);
        for (Continuation cc = Continuation.startWith(new ExecutionInner(i)); null != cc; cc = cc.resume()) {

            System.out.println("\tFrom inner " + cc.value());
            Continuation.suspend(i);
        }//w w w  . ja  v  a2  s .  c o m
    }
}

From source file:org.apache.commons.javaflow.examples.simple.Execution.java

@Override
public @continuable void run() {
    for (int i = 1; i <= 5; i++) {
        System.out.println("Exe before suspend");
        Object fromCaller = Continuation.suspend(i);
        System.out.println("Exe after suspend: " + fromCaller);
    }/*from  w w w .j a va2 s. c o m*/
}