Class UniAwaitOptional<T>

  • Type Parameters:
    T - the type of the item

    public class UniAwaitOptional<T>
    extends java.lang.Object
    Likes UniAwait but wrapping the item event into an Optional. This optional is empty if the Uni fires null.
    See Also:
    Uni.await()
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Optional<T> atMost​(java.time.Duration duration)
      Subscribes to the Uni and waits (blocking the caller thread) at most the given duration until an item or failure is fired by the upstream uni.
      java.util.Optional<T> indefinitely()
      Subscribes to the Uni and waits (blocking the caller thread) indefinitely until a item event is fired or a failure event is fired by the upstream uni.
      • Methods inherited from class java.lang.Object

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

      • UniAwaitOptional

        public UniAwaitOptional​(Uni<T> upstream,
                                Context context)
    • Method Detail

      • indefinitely

        public java.util.Optional<T> indefinitely()
        Subscribes to the Uni and waits (blocking the caller thread) indefinitely until a item event is fired or a failure event is fired by the upstream uni.

        If the Uni fires an item, it returns that item wrapped into an Optional. If the item is null the returned optional is empty. If the Uni fires a failure, the original exception is thrown (wrapped in a CompletionException it's a checked exception).

        Note that each call to this method triggers a new subscription.

        Returns:
        the item from the Uni wrapped into an Optional, empty if the Uni is resolved with null
      • atMost

        public java.util.Optional<T> atMost​(java.time.Duration duration)
        Subscribes to the Uni and waits (blocking the caller thread) at most the given duration until an item or failure is fired by the upstream uni.

        If the Uni fires an item, it returns that item wrapped into an Optional. If the item is null the returned optional is empty. If the Uni fires a failure, the original exception is thrown (wrapped in a CompletionException it's a checked exception). If the timeout is reached before completion, a TimeoutException is thrown.

        Note that each call to this method triggers a new subscription.

        Parameters:
        duration - the duration, must not be null, must not be negative or zero.
        Returns:
        the item from the Uni, potentially null