Class SequentialProcessor

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class SequentialProcessor
    extends java.lang.Object
    implements java.lang.AutoCloseable
    Async processor that serializes the execution of tasks such that no two tasks execute at the same time.
    • Constructor Summary

      Constructors 
      Constructor Description
      SequentialProcessor​(@NonNull java.util.concurrent.Executor executor)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <ReturnType>
      java.util.concurrent.CompletableFuture<ReturnType>
      add​(java.util.function.Supplier<java.util.concurrent.CompletableFuture<? extends ReturnType>> toRun)
      Queues up a new task to execute.
      void close()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SequentialProcessor

        @ConstructorProperties("executor")
        public SequentialProcessor​(@NonNull
                                   @NonNull java.util.concurrent.Executor executor)
    • Method Detail

      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
      • add

        public <ReturnType> java.util.concurrent.CompletableFuture<ReturnType> add​(java.util.function.Supplier<java.util.concurrent.CompletableFuture<? extends ReturnType>> toRun)
        Queues up a new task to execute. This task will not begin execution until all previous tasks have finished. In addition, no subsequent task will begin executing until this task has finished executing.
        Type Parameters:
        ReturnType - Return type.
        Parameters:
        toRun - A Supplier that will be invoked when it is this task's turn to run. It will return a CompletableFuture that will complete when this task completes.
        Returns:
        A CompletableFuture that will complete with the result from the CompletableFuture returned by toRun, when toRun completes executing.