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 Deprecated Methods Modifier and Type Method Description <R> Uni<R>apply(java.util.function.Function<? super T,? extends R> mapper)Deprecated.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.Uni<T>invokeUni(java.util.function.Function<? super T,Uni<?>> action)Deprecated.Usecall(Function)<R> Uni<R>produceCompletionStage(java.util.function.Function<? super T,? extends java.util.concurrent.CompletionStage<? extends R>> mapper)Deprecated.UsetransformToUni(Function)and produce the Uni usingUni.createFrom().completionStage(...)<R> Multi<R>produceMulti(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends R>> mapper)Deprecated.<R> Uni<R>produceUni(java.util.function.BiConsumer<? super T,UniEmitter<? super R>> consumer)Deprecated.<R> Uni<R>produceUni(java.util.function.Function<? super T,Uni<? extends R>> mapper)Deprecated.UsetransformToUni(Function)instead<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 thisUniproduces its item (maybenull), call the givenmapperto 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 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
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
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
-
invokeUni
@Deprecated public Uni<T> invokeUni(java.util.function.Function<? super T,Uni<?>> action)
Deprecated.Usecall(Function)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
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
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.
-
apply
@Deprecated public <R> Uni<R> apply(java.util.function.Function<? super T,? extends R> mapper)
Deprecated.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
-
transform
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
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.
-
produceUni
@Deprecated public <R> Uni<R> produceUni(java.util.function.Function<? super T,Uni<? extends R>> mapper)
Deprecated.UsetransformToUni(Function)insteadTransforms 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
public <R> Multi<R> transformToMulti(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends R>> mapper)
When thisUniproduces its item (maybenull), call the givenmapperto produce aPublisher. Continue the pipeline with this publisher (as aMulti).The mapper is called with the item event of the current
Uniand produces aPublisher, possibly using another type of item (R). Events fired by the producedPublisherare 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
-
produceMulti
@Deprecated public <R> Multi<R> produceMulti(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends R>> mapper)
Deprecated.When thisUniproduces its item (maybenull), call the givenmapperto produce aPublisher. Continue the pipeline with this publisher (as aMulti).The mapper is called with the item event of the current
Uniand produces aPublisher, possibly using another type of item (R). Events fired by the producedPublisherare 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
-
produceCompletionStage
@Deprecated public <R> Uni<R> produceCompletionStage(java.util.function.Function<? super T,? extends java.util.concurrent.CompletionStage<? extends R>> mapper)
Deprecated.UsetransformToUni(Function)and produce the Uni usingUni.createFrom().completionStage(...)Transforms the received item asynchronously, forwarding the events emitted by anotherCompletionStageproduced by the givenmapper.The mapper is called with the item event of the current
Uniand produces anCompletionStage, possibly using another type of item (R). The events fired by producedCompletionStageare forwarded to theUnireturned by this method.*
- Type Parameters:
R- the type of item- Parameters:
mapper- the function called with the item of thisUniand producing theCompletionStage, must not benull, must not returnnull.- Returns:
- a new
Unithat would fire events from the uni produced by the mapper function, possibly in an asynchronous manner.
-
transformToUni
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.
-
produceUni
@Deprecated public <R> Uni<R> produceUni(java.util.function.BiConsumer<? super T,UniEmitter<? super R>> consumer)
Deprecated.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
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
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
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
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
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
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
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
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,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
-
-