Module stormpot
Package stormpot

Interface Completion

All Superinterfaces:
Flow.Publisher<Void>, ForkJoinPool.ManagedBlocker
All Known Implementing Classes:
StackCompletion

public interface Completion extends ForkJoinPool.ManagedBlocker, Flow.Publisher<Void>
A Completion represents some task that is going to be completed at some point in the future, or maybe already has completed. It is similar to 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 Details

    • from

      static Completion from(CompletionStage<?> stage)
      Translate the given CompletionStage into a Stormpot Completion.
      Parameters:
      stage - The CompletionStage.
      Returns:
      A Completion that completes when the given stage completes.
    • from

      static Completion from(Consumer<Runnable> completionCallback)
      Create a completion using the given callback handler. The Consumer argument will be given a Runnable instance, which will complete the Completion when the Runnable.run() method is called.
      Parameters:
      completionCallback - The handler controlling the completion.
      Returns:
      A Completion that completes when the given Runnable.run() method is called.
    • await

      boolean await(Timeout timeout) throws InterruptedException
      Causes the current thread to wait until the completion is finished, or the thread is interrupted, 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 InterruptedException is 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:
      true if the task represented by this completion completed within the specified waiting time, or was already complete upon entry to this method; or false if the specified Timeout elapsed before the task could finish.
      Throws:
      InterruptedException - if the current thread is interrupted while waiting.
      IllegalArgumentException - if the provided timeout parameter is null.
    • isCompleted

      boolean isCompleted()
      Immediately return whether the completion has completed or not.
      Returns:
      true if this completion has completed, otherwise false.