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();
}
Aggregations