package net.goldolphin.cate;

/**
 * Context of current control flow.
 * @param <TInput>
 * @param <TResult>
 */
public class Context<TInput, TResult> {
    private final TInput state;
    private final IContinuation cont;
    private final IContinuation subCont;
    private final IScheduler scheduler;

    /**
     * Constructor.
     * @param state
     * @param cont
     * @param subCont
     * @param scheduler
     */
    Context(TInput state, IContinuation cont, IContinuation subCont, IScheduler scheduler) {
        this.state = state;
        this.cont = cont;
        this.subCont = subCont;
        this.scheduler = scheduler;
    }

    /**
     * Get current state.
     * @return
     */
    public TInput getState() {
        return state;
    }

    /**
     * Get current scheduler.
     * @return
     */
    public IScheduler getScheduler() {
        return scheduler;
    }

    /**
     * Resume the control flow with specified new state in former scheduler.
     * @param newState
     */
    public void resume(TResult newState) {
        scheduler.schedule(newState, cont, subCont);
    };

    /**
     * Resume the control flow with specified new state synchronously.
     * @param newState
     */
    public void resumeSynchronously(TResult newState) {
        cont.apply(newState, subCont, scheduler);
    }
}

@@ -1113,230 +1113,7 @@
   %7D;
-%0A%0A    /**%0A     * Resume the control flow with specified new state synchronously.%0A     * @param newState%0A     */%0A    public void resumeSynchronously(TResult newState) %7B%0A        cont.apply(newState, subCont, scheduler);%0A    %7D
 %0A%7D%0A

make Timer.withTimeout generate stateless task.