Class UniOnItem<T>
- java.lang.Object
-
- io.smallrye.mutiny.groups.UniOnItem<T>
-
public class UniOnItem<T> extends java.lang.Object
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Uni<T>
call(java.util.function.Function<? super T,Uni<?>> action)
Produces a newUni
invoking the given @{code action} when theitem
event is received.Uni<T>
call(java.util.function.Supplier<Uni<?>> action)
Produces a newUni
invoking the given @{code action} when theitem
event is received, ignoring it.<O> Uni<O>
castTo(java.lang.Class<O> target)
Produces anUni
emitting an item based on the upstream item but casted to the target class.UniOnItemDelay<T>
delayIt()
Produces a newUni
receiving an item from upstream and delaying the emission on theitem
event (with the same item).<O> Multi<O>
disjoint()
Uni<T>
failWith(java.util.function.Function<? super T,? extends java.lang.Throwable> mapper)
Uni<T>
failWith(java.util.function.Supplier<? extends java.lang.Throwable> supplier)
UniOnNotNull<T>
ifNotNull()
Adds specific behavior when the observedUni
fies anon-null
item.UniOnNull<T>
ifNull()
Adds specific behavior when the observedUni
firesnull
as item.UniOnItemIgnore<T>
ignore()
Produces aUni
ignoring the item of the currentUni
and continuing with eitheranother item
,a failure
, oranother Uni
.Uni<T>
invoke(java.lang.Runnable callback)
Produces a newUni
invoking the given callback when theitem
event is fired, ignoring its value.Uni<T>
invoke(java.util.function.Consumer<? super T> callback)
Produces a newUni
invoking the given callback when theitem
event is fired.<R> Uni<R>
transform(java.util.function.Function<? super T,? extends R> mapper)
<R> Multi<R>
transformToMulti(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends R>> mapper)
When thisUni
produces its item (maybenull
), call the givenmapper
to produce aPublisher
.<R> Uni<R>
transformToUni(java.util.function.BiConsumer<? super T,UniEmitter<? super R>> consumer)
Transforms the received item asynchronously, forwarding the events emitted by anUniEmitter
provided to the given consumer.<R> Uni<R>
transformToUni(java.util.function.Function<? super T,Uni<? extends R>> mapper)
Transforms the received item asynchronously, forwarding the events emitted by anotherUni
produced by the givenmapper
.
-
-
-
Method Detail
-
invoke
@CheckReturnValue public Uni<T> invoke(java.util.function.Consumer<? super T> callback)
Produces a newUni
invoking the given callback when theitem
event is fired. Note that the item can benull
.If the callback throws an exception, this exception is propagated to the downstream as failure.
- Parameters:
callback
- the callback, must not benull
- Returns:
- the new
Uni
-
invoke
@CheckReturnValue public Uni<T> invoke(java.lang.Runnable callback)
Produces a newUni
invoking the given callback when theitem
event is fired, ignoring its value.If the callback throws an exception, this exception is propagated to the downstream as failure.
- Parameters:
callback
- the callback, must not benull
- Returns:
- the new
Uni
-
call
@CheckReturnValue public Uni<T> call(java.util.function.Function<? super T,Uni<?>> action)
Produces a newUni
invoking the given @{code action} when theitem
event is received. Note that the received item can benull
.Unlike
invoke(Consumer)
, the passed function returns aUni
. When the producedUni
sends its item, this item is discarded, and the originalitem
is forwarded downstream. If the producedUni
fails, the failure is propagated downstream.
-
call
@CheckReturnValue public Uni<T> call(java.util.function.Supplier<Uni<?>> action)
Produces a newUni
invoking the given @{code action} when theitem
event is received, ignoring it.Unlike
invoke(Consumer)
, the passed function returns aUni
. When the producedUni
sends its item, this item is discarded, and the originalitem
is forwarded downstream. If the producedUni
fails, the failure is propagated downstream.
-
transform
@CheckReturnValue public <R> Uni<R> transform(java.util.function.Function<? super T,? extends R> mapper)
Produces a newUni
invoking the given function when the currentUni
fires theitem
event. The function receives the item as parameter, and can transform it. The returned object is sent downstream asitem
.For asynchronous composition, see
transformToUni(Function)
.- Type Parameters:
R
- the type of Uni item- Parameters:
mapper
- the mapper function, must not benull
- Returns:
- the new
Uni
-
transformToUni
@CheckReturnValue public <R> Uni<R> transformToUni(java.util.function.Function<? super T,Uni<? extends R>> mapper)
Transforms the received item asynchronously, forwarding the events emitted by anotherUni
produced by the givenmapper
.The mapper is called with the item event of the current
Uni
and produces anUni
, possibly using another type of item (R
). The events fired by producedUni
are forwarded to theUni
returned by this method.This operation is generally named
flatMap
.
-
transformToMulti
@CheckReturnValue public <R> Multi<R> transformToMulti(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends R>> mapper)
When thisUni
produces its item (maybenull
), call the givenmapper
to produce aPublisher
. Continue the pipeline with this publisher (as aMulti
).The mapper is called with the item event of the current
Uni
and produces aPublisher
, possibly using another type of item (R
). Events fired by the producedPublisher
are forwarded to theMulti
returned by this method.This operation is generally named
flatMapPublisher
.- Type Parameters:
R
- the type of item produced by the resultingMulti
- Parameters:
mapper
- the mapper, must not benull
, may expect to receivenull
as item.- Returns:
- the multi
-
transformToUni
@CheckReturnValue public <R> Uni<R> transformToUni(java.util.function.BiConsumer<? super T,UniEmitter<? super R>> consumer)
Transforms the received item asynchronously, forwarding the events emitted by anUniEmitter
provided to the given consumer.The consumer is called with the item event of the current
Uni
and an emitter used to fire events. These events are these propagated by the producedUni
.- Type Parameters:
R
- the type of item emitted by the emitter- Parameters:
consumer
- the function called with the item of the thisUni
and anUniEmitter
. It must not benull
.- Returns:
- a new
Uni
that would fire events from the emitter consumed by the mapper function, possibly in an asynchronous manner.
-
delayIt
@CheckReturnValue public UniOnItemDelay<T> delayIt()
Produces a newUni
receiving an item from upstream and delaying the emission on theitem
event (with the same item).- Returns:
- the object to configure the delay.
-
ignore
@CheckReturnValue public UniOnItemIgnore<T> ignore()
Produces aUni
ignoring the item of the currentUni
and continuing with eitheranother item
,a failure
, oranother Uni
. The producedUni
propagates the failure event if the upstream uni fires a failure.Examples:
Uni<T> upstream = ...; uni = upstream.onItem().ignore().andSwitchTo(other) // Ignore the item from upstream and switch to another uni uni = upstream.onItem().ignore().andContinueWith(newResult) // Ignore the item from upstream, and fire newResult
- Returns:
- the object to configure the continuation logic.
-
failWith
@CheckReturnValue public Uni<T> failWith(java.util.function.Function<? super T,? extends java.lang.Throwable> mapper)
Produces a newUni
invoking the given function when the currentUni
fires an item. The function transforms the received item into a failure that will be fired by the producedUni
. For asynchronous composition, seetransformToUni(Function)
}.- Parameters:
mapper
- the mapper function, must not benull
, must not returnnull
- Returns:
- the new
Uni
-
failWith
@CheckReturnValue public Uni<T> failWith(java.util.function.Supplier<? extends java.lang.Throwable> supplier)
Produces a newUni
invoking the given supplier when the currentUni
fires an item. The supplier produce the received item into a failure that will be fired by the producedUni
.- Parameters:
supplier
- the supplier to produce the failure, must not benull
, must not producenull
- Returns:
- the new
Uni
-
castTo
@CheckReturnValue public <O> Uni<O> castTo(java.lang.Class<O> target)
Produces anUni
emitting an item based on the upstream item but casted to the target class.- Type Parameters:
O
- the type of item emitted by the produced uni- Parameters:
target
- the target class- Returns:
- the new Uni
-
ifNull
@CheckReturnValue public UniOnNull<T> ifNull()
Adds specific behavior when the observedUni
firesnull
as item. Whilenull
is a valid value, it may require specific processing. This group of operators allows implementing this specific behavior.Examples:
Uni<T> upstream = ...; Uni<T> uni = ...; uni = upstream.onItem().ifNull().continueWith(anotherValue) // use the fallback value if upstream emits null uni = upstream.onItem().ifNull().fail() // propagate a NullPointerException if upstream emits null uni = upstream.onItem().ifNull().failWith(exception) // propagate the given exception if upstream emits null uni = upstream.onItem().ifNull().switchTo(another) // switch to another uni if upstream emits null
- Returns:
- the object to configure the behavior when receiving
null
-
ifNotNull
@CheckReturnValue public UniOnNotNull<T> ifNotNull()
Adds specific behavior when the observedUni
fies anon-null
item. If the item isnull
, default fallbacks are used.- Returns:
- the object to configure the behavior when receiving a
non-null
item
-
disjoint
@CheckReturnValue public <O> Multi<O> disjoint()
Takes the items from the upstreamUni
that is either aPublisher<O>
, anO[]
, anIterable<O>
or aMulti<O>
and disjoint the items to obtain aMulti<O>
.For examples,
Uni<[A, B, C]>
is transformed intoMulti<A, B, C>
,Uni<[]>
is transformed into an emptyMulti
.If the item from the upstream are not instances of
Iterable
,Publisher
or array, anIllegalArgumentException
is propagated downstream.If the item is
null
, an emptyMulti
is produced. If the upstream propagates a failure, the failure is propagated downstream.- Type Parameters:
O
- the type of the upstream item.- Returns:
- the resulting multi
-
-