Package io.pravega.common.concurrent
Class SequentialProcessor
- java.lang.Object
-
- io.pravega.common.concurrent.SequentialProcessor
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class SequentialProcessor extends java.lang.Object implements java.lang.AutoCloseableAsync 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.voidclose()
-
-
-
Method Detail
-
close
public void close()
- Specified by:
closein interfacejava.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.
-
-