Package io.smallrye.mutiny.groups
Class UniAwaitOptional<T>
- java.lang.Object
-
- io.smallrye.mutiny.groups.UniAwaitOptional<T>
-
- Type Parameters:
T
- the type of the item
public class UniAwaitOptional<T> extends java.lang.Object
LikesUniAwait
but wrapping the item event into anOptional
. This optional is empty if theUni
firesnull
.- See Also:
Uni.await()
-
-
Constructor Summary
Constructors Constructor Description UniAwaitOptional(Uni<T> upstream, Context context)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Optional<T>
atMost(java.time.Duration duration)
Subscribes to theUni
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 theUni
and waits (blocking the caller thread) indefinitely until aitem
event is fired or afailure
event is fired by the upstream uni.
-
-
-
Method Detail
-
indefinitely
public java.util.Optional<T> indefinitely()
Subscribes to theUni
and waits (blocking the caller thread) indefinitely until aitem
event is fired or afailure
event is fired by the upstream uni.If the
Uni
fires an item, it returns that item wrapped into anOptional
. If the item isnull
the returned optional is empty. If theUni
fires a failure, the original exception is thrown (wrapped in aCompletionException
it's a checked exception).Note that each call to this method triggers a new subscription.
-
atMost
public java.util.Optional<T> atMost(java.time.Duration duration)
Subscribes to theUni
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 anOptional
. If the item isnull
the returned optional is empty. If theUni
fires a failure, the original exception is thrown (wrapped in aCompletionException
it's a checked exception). If the timeout is reached before completion, aTimeoutException
is thrown.Note that each call to this method triggers a new subscription.
- Parameters:
duration
- the duration, must not benull
, must not be negative or zero.- Returns:
- the item from the
Uni
, potentiallynull
-
-