Interface OptionalCompletionStage<T>

  • Type Parameters:
    T - return type of the asynchronous operation
    All Superinterfaces:
    CompletionStage<Optional<T>>

    public interface OptionalCompletionStage<T>
    extends CompletionStage<Optional<T>>
    A completion stage that allows processing of cases when the element is present and when not.
    • Method Detail

      • onEmpty

        OptionalCompletionStage<T> onEmpty​(Runnable action)
        Returns a new OptionalCompletionStage that, when this stage completes normally and returns null, executes the given action.
        Parameters:
        action - the action to perform before completing the returned OptionalCompletionStage
        Returns:
        the new OptionalCompletionStage
      • onValue

        OptionalCompletionStage<T> onValue​(Consumer<? super T> action)
        Returns a new OptionalCompletionStage that, when this stage completes normally and returns non-null, is executed with this stage's result as the argument to the supplied action.
        Parameters:
        action - the action to perform before completing the returned OptionalCompletionStage
        Returns:
        the new OptionalCompletionStage
      • create

        static <T> OptionalCompletionStage<T> create​(CompletionStage<Optional<T>> originalStage)
        Creates a new instance of the completion stage that allows processing of cases when the element is present and when not.
        Type Parameters:
        T - return type of the asynchronous operation
        Parameters:
        originalStage - source completion stage instance
        Returns:
        the new OptionalCompletionStage