/** * Runs the Coroutine until it is finished or suspended. This method must only be called when the * Coroutine is in the states NEW or SUSPENDED. It is not multi threading safe. * * @throws java.lang.IllegalStateException if the Coroutine is currently running or already * finished. */ public void run() throws IllegalStateException { if (state != State.NEW && state != State.SUSPENDED) { throw new IllegalStateException("Not new or suspended"); } State result = State.FINISHED; Stack oldStack = Stack.getStack(); try { state = State.RUNNING; Stack.setStack(stack); try { proto.coExecute(); } catch (SuspendExecution ex) { assert ex == SuspendExecution.instance; result = State.SUSPENDED; // stack.dump(); stack.resumeStack(); } } finally { Stack.setStack(oldStack); state = result; } }