- 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 newUniinvoking the given @{code action} when theitemevent is received.Uni<T>call(java.util.function.Supplier<Uni<?>> action)Produces a newUniinvoking the given @{code action} when theitemevent is received, ignoring it.<O> Uni<O>castTo(java.lang.Class<O> target)Produces anUniemitting an item based on the upstream item but casted to the target class.UniOnItemDelay<T>delayIt()Produces a newUnireceiving an item from upstream and delaying the emission on theitemevent (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 observedUnifies anon-nullitem.UniOnNull<T>ifNull()Adds specific behavior when the observedUnifiresnullas item.UniOnItemIgnore<T>ignore()Produces aUniignoring the item of the currentUniand continuing with eitheranother item,a failure, oranother Uni.Uni<T>invoke(java.lang.Runnable callback)Produces a newUniinvoking the given callback when theitemevent is fired, ignoring its value.Uni<T>invoke(java.util.function.Consumer<? super T> callback)Produces a newUniinvoking the given callback when theitemevent 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 java.util.concurrent.Flow.Publisher<? extends R>> mapper)When thisUniproduces its item (maybenull), call the givenmapperto produce aFlow.Publisher.<R> Uni<R>transformToUni(java.util.function.BiConsumer<? super T,UniEmitter<? super R>> consumer)Transforms the received item asynchronously, forwarding the events emitted by anUniEmitterprovided 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 anotherUniproduced by the givenmapper.
-
-
-
Method Detail
-
invoke
@CheckReturnValue public Uni<T> invoke(java.util.function.Consumer<? super T> callback)
Produces a newUniinvoking the given callback when theitemevent 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 newUniinvoking the given callback when theitemevent 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 newUniinvoking the given @{code action} when theitemevent is received. Note that the received item can benull.Unlike
invoke(Consumer), the passed function returns aUni. When the producedUnisends its item, this item is discarded, and the originalitemis forwarded downstream. If the producedUnifails, the failure is propagated downstream.
-
call
@CheckReturnValue public Uni<T> call(java.util.function.Supplier<Uni<?>> action)
Produces a newUniinvoking the given @{code action} when theitemevent is received, ignoring it.Unlike
invoke(Consumer), the passed function returns aUni. When the producedUnisends its item, this item is discarded, and the originalitemis forwarded downstream. If the producedUnifails, the failure is propagated downstream.
-
transform
@CheckReturnValue public <R> Uni<R> transform(java.util.function.Function<? super T,? extends R> mapper)
Produces a newUniinvoking the given function when the currentUnifires theitemevent. 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 anotherUniproduced by the givenmapper.The mapper is called with the item event of the current
Uniand produces anUni, possibly using another type of item (R). The events fired by producedUniare forwarded to theUnireturned by this method.This operation is generally named
flatMap.
-
transformToMulti
@CheckReturnValue public <R> Multi<R> transformToMulti(java.util.function.Function<? super T,? extends java.util.concurrent.Flow.Publisher<? extends R>> mapper)
When thisUniproduces its item (maybenull), call the givenmapperto produce aFlow.Publisher. Continue the pipeline with this publisher (as aMulti).The mapper is called with the item event of the current
Uniand produces aFlow.Publisher, possibly using another type of item (R). Events fired by the producedFlow.Publisherare forwarded to theMultireturned 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 receivenullas 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 anUniEmitterprovided to the given consumer.The consumer is called with the item event of the current
Uniand 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 thisUniand anUniEmitter. It must not benull.- Returns:
- a new
Unithat would fire events from the emitter consumed by the mapper function, possibly in an asynchronous manner.
-
delayIt
@CheckReturnValue public UniOnItemDelay<T> delayIt()
Produces a newUnireceiving an item from upstream and delaying the emission on theitemevent (with the same item).- Returns:
- the object to configure the delay.
-
ignore
@CheckReturnValue public UniOnItemIgnore<T> ignore()
Produces aUniignoring the item of the currentUniand continuing with eitheranother item,a failure, oranother Uni. The producedUnipropagates 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 newUniinvoking the given function when the currentUnifires 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 newUniinvoking the given supplier when the currentUnifires 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 anUniemitting 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 observedUnifiresnullas item. Whilenullis 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 observedUnifies anon-nullitem. If the item isnull, default fallbacks are used.- Returns:
- the object to configure the behavior when receiving a
non-nullitem
-
disjoint
@CheckReturnValue public <O> Multi<O> disjoint()
Takes the items from the upstreamUnithat 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,Flow.Publisheror array, anIllegalArgumentExceptionis propagated downstream.If the item is
null, an emptyMultiis 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
-
-