Class RunnableWithCallback

  • All Implemented Interfaces:
    Runnable

    public class RunnableWithCallback
    extends Object
    implements Runnable
    A runnable wrapper which can be useful to schedule a task with a specific delay and invoking a callback once the runnable finished executing.

    e.g. conditional task rescheduling

     Callback callback = {
          //Check if we want to reschedule a new task
          Runnable rescheduledTask = new Task();
          Exector.schedule(new RunnableWithCallBack(rescheduledTask,this),newDelay,timeunit); 
     };
     
     Runnable task = new Task();
     RunnableWithCallback wrapper = new RunnableWithCallback(task,callback);
     Executor.shedule(wrapper,initialDelay,TimeUnit.seconds);
     
    Since:
    1.0.0 com.github.kilianB
    Author:
    Kilian
    • Constructor Detail

      • RunnableWithCallback

        public RunnableWithCallback​(Runnable task,
                                    Runnable callback)
        Parameters:
        task - The task to execute
        callback - executed after task finished
    • Method Detail

      • run

        public void run()
        Specified by:
        run in interface Runnable