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

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

Introduction

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

Prototype

public static void cancel() 

Source Link

Document

Jumps to where the execution was resumed, and suspend execution.

Usage

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

@Override
public @continuable void run() {
    final Object[] array = new String[] { "A", "C", "B" };
    try {//from w  w  w .  j  av a 2s  .c  om
        int i = 1;
        System.out.println("Before suspend");
        Continuation.suspend("XYZ");
        System.out.println("After suspend #" + (i++) + ", should not mutate!!!");
        Continuation.cancel();
        // The line below will never be called -- 
        // first we are canceling continuation
        // then we are destroying it
        array[1] = "CHANGED";
    } finally {
        // This will be called only after cc.destroy() from outer code
        System.out.println("Finally is called, array value is " + Arrays.asList(array));
    }
}