- All Superinterfaces:
Flow.Publisher<Void>,ForkJoinPool.ManagedBlocker
- All Known Implementing Classes:
StackCompletion
Future but without any options for
cancellation or returning a result.
Completions implement the ForkJoinPool.ManagedBlocker interface, so they can
be safely used with ForkJoinPool.managedBlock(ManagedBlocker).
Completions are also Flow.Publisher of Void.
No messages or exceptions are ever published, but the
Flow.Subscriber.onComplete() methods will be called when the
completion is completed.
If the completion has already completed, then the
Flow.Subscriber.onComplete() method will be called immediately
from Flow.Publisher.subscribe(Flow.Subscriber).
- Author:
- Chris Vest
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleanCauses the current thread to wait until the completion is finished, or the thread isinterrupted, or the specified waiting time elapses.static Completionfrom(CompletionStage<?> stage) Translate the givenCompletionStageinto a StormpotCompletion.static CompletionCreate a completion using the given callback handler.booleanImmediately return whether the completion has completed or not.Methods inherited from interface java.util.concurrent.Flow.Publisher
subscribeMethods inherited from interface java.util.concurrent.ForkJoinPool.ManagedBlocker
block, isReleasable
-
Method Details
-
from
Translate the givenCompletionStageinto a StormpotCompletion.- Parameters:
stage- TheCompletionStage.- Returns:
- A
Completionthat completes when the given stage completes.
-
from
Create a completion using the given callback handler. TheConsumerargument will be given aRunnableinstance, which will complete theCompletionwhen theRunnable.run()method is called.- Parameters:
completionCallback- The handler controlling the completion.- Returns:
- A
Completionthat completes when the givenRunnable.run()method is called.
-
await
Causes the current thread to wait until the completion is finished, or the thread isinterrupted, or the specified waiting time elapses.If the task represented by this completion has already completed, the method immediately returns
true.If the current thread already has its interrupted status set upon entry to this method, or the thread is interrupted while waiting, then an
InterruptedExceptionis thrown and the current threads interrupted status is cleared.If the specified waiting time elapses, then the method returns
false.- Parameters:
timeout- The timeout delimiting the maximum time to wait for the task to complete. Timeouts with zero or negative values will cause the method to return immediately.- Returns:
trueif the task represented by this completion completed within the specified waiting time, or was already complete upon entry to this method; orfalseif the specified Timeout elapsed before the task could finish.- Throws:
InterruptedException- if the current thread is interrupted while waiting.IllegalArgumentException- if the providedtimeoutparameter isnull.
-
isCompleted
boolean isCompleted()Immediately return whether the completion has completed or not.- Returns:
trueif this completion has completed, otherwisefalse.
-