Search in sources :

Example 1 with Block

use of com.cloudbees.groovy.cps.Block in project groovy-cps by cloudbees.

the class GreenThread method start.

/**
     * Creates a new green thread that executes the given closure.
     */
public void start() {
    Block b;
    try {
        run();
        // closure had run synchronously.
        b = Block.NOOP;
    } catch (CpsCallableInvocation inv) {
        // this will create a thread, and resume with the newly created thread
        b = inv.asBlock();
    } catch (Throwable t) {
        // closure had run synchronously and failed
        b = new ThrowBlock(new ConstantBlock(t));
    }
    final Block bb = b;
    invoke(new ThreadTask() {

        public Result eval(GreenWorld w) {
            w = w.withNewThread(new GreenThreadState(GreenThread.this, bb));
            return new Result(w, new Outcome(GreenThread.this, null), false);
        }
    });
    // thus the code will never reach here
    throw new AssertionError();
}
Also used : ThrowBlock(com.cloudbees.groovy.cps.impl.ThrowBlock) ConstantBlock(com.cloudbees.groovy.cps.impl.ConstantBlock) CpsCallableInvocation(com.cloudbees.groovy.cps.impl.CpsCallableInvocation) Outcome(com.cloudbees.groovy.cps.Outcome) Block(com.cloudbees.groovy.cps.Block) ConstantBlock(com.cloudbees.groovy.cps.impl.ConstantBlock) ThrowBlock(com.cloudbees.groovy.cps.impl.ThrowBlock)

Aggregations

Block (com.cloudbees.groovy.cps.Block)1 Outcome (com.cloudbees.groovy.cps.Outcome)1 ConstantBlock (com.cloudbees.groovy.cps.impl.ConstantBlock)1 CpsCallableInvocation (com.cloudbees.groovy.cps.impl.CpsCallableInvocation)1 ThrowBlock (com.cloudbees.groovy.cps.impl.ThrowBlock)1