Class UniAwait<T>

java.lang.Object
io.smallrye.mutiny.groups.UniAwait<T>
Type Parameters:
T - the type of item

public class UniAwait<T> extends Object
Waits and returns the item emitted by the Uni. If the Uni receives a failure, the failure is thrown.

This class lets you configure how to retrieves the item of a Uni by blocking the caller thread.

See Also:
  • Constructor Details

    • UniAwait

      public UniAwait(Uni<T> upstream, Context context)
  • Method Details

    • indefinitely

      public 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, potentially null if the operation returns null. 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, potentially null
    • atMost

      public T atMost(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, potentially null if the operation returns null. 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
    • asOptional

      @CheckReturnValue public UniAwaitOptional<T> asOptional()
      Indicates that you are awaiting for the item event of the attached Uni wrapped into an Optional. So if the Uni fires null as item, you receive an empty Optional.
      Returns:
      the UniAwaitOptional configured to produce an Optional.