Class UniOnItem<T>

java.lang.Object
io.smallrye.mutiny.groups.UniOnItem<T>

public class UniOnItem<T> extends Object
  • Constructor Details

    • UniOnItem

      public UniOnItem(Uni<T> upstream)
  • Method Details

    • invoke

      @CheckReturnValue public Uni<T> invoke(Consumer<? super T> callback)
      Produces a new Uni invoking the given callback when the item event is fired. Note that the item can be null.

      If the callback throws an exception, this exception is propagated to the downstream as failure.

      Parameters:
      callback - the callback, must not be null
      Returns:
      the new Uni
    • invoke

      @CheckReturnValue public Uni<T> invoke(Runnable callback)
      Produces a new Uni invoking the given callback when the item 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 be null
      Returns:
      the new Uni
    • call

      @CheckReturnValue public Uni<T> call(Function<? super T,Uni<?>> action)
      Produces a new Uni invoking the given @{code action} when the item event is received. Note that the received item can be null.

      Unlike invoke(Consumer), the passed function returns a Uni. When the produced Uni sends its item, this item is discarded, and the original item is forwarded downstream. If the produced Uni fails, the failure is propagated downstream.

      Parameters:
      action - the function taking the item and returning a Uni, must not be null, must not return null
      Returns:
      the new Uni
    • call

      @CheckReturnValue public Uni<T> call(Supplier<Uni<?>> action)
      Produces a new Uni invoking the given @{code action} when the item event is received, ignoring it.

      Unlike invoke(Consumer), the passed function returns a Uni. When the produced Uni sends its item, this item is discarded, and the original item is forwarded downstream. If the produced Uni fails, the failure is propagated downstream.

      Parameters:
      action - the action returning a Uni, must not be null, must not return null
      Returns:
      the new Uni
    • transform

      @CheckReturnValue public <R> Uni<R> transform(Function<? super T,? extends R> mapper)
      Produces a new Uni invoking the given function when the current Uni fires the item event. The function receives the item as parameter, and can transform it. The returned object is sent downstream as item.

      For asynchronous composition, see transformToUni(Function).

      Type Parameters:
      R - the type of Uni item
      Parameters:
      mapper - the mapper function, must not be null
      Returns:
      the new Uni
    • transformToUni

      @CheckReturnValue public <R> Uni<R> transformToUni(Function<? super T,Uni<? extends R>> mapper)
      Transforms the received item asynchronously, forwarding the events emitted by another Uni produced by the given mapper.

      The mapper is called with the item event of the current Uni and produces an Uni, possibly using another type of item (R). The events fired by produced Uni are forwarded to the Uni returned by this method.

      This operation is generally named flatMap.

      Type Parameters:
      R - the type of item
      Parameters:
      mapper - the function called with the item of this Uni and producing the Uni, must not be null, must not return null.
      Returns:
      a new Uni that would fire events from the uni produced by the mapper function, possibly in an asynchronous manner.
    • transformToMulti

      @CheckReturnValue public <R> Multi<R> transformToMulti(Function<? super T,? extends Flow.Publisher<? extends R>> mapper)
      When this Uni produces its item (maybe null), call the given mapper to produce a Flow.Publisher. Continue the pipeline with this publisher (as a Multi).

      The mapper is called with the item event of the current Uni and produces a Flow.Publisher, possibly using another type of item (R). Events fired by the produced Flow.Publisher are forwarded to the Multi returned by this method.

      This operation is generally named flatMapPublisher.

      Type Parameters:
      R - the type of item produced by the resulting Multi
      Parameters:
      mapper - the mapper, must not be null, may expect to receive null as item.
      Returns:
      the multi
    • transformToUni

      @CheckReturnValue public <R> Uni<R> transformToUni(BiConsumer<? super T,UniEmitter<? super R>> consumer)
      Transforms the received item asynchronously, forwarding the events emitted by an UniEmitter 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 produced Uni.

      Type Parameters:
      R - the type of item emitted by the emitter
      Parameters:
      consumer - the function called with the item of the this Uni and an UniEmitter. It must not be null.
      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 new Uni receiving an item from upstream and delaying the emission on the item event (with the same item).
      Returns:
      the object to configure the delay.
    • ignore

      @CheckReturnValue public UniOnItemIgnore<T> ignore()
      Produces a Uni ignoring the item of the current Uni and continuing with either another item, a failure, or another Uni. The produced Uni 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(Function<? super T,? extends Throwable> mapper)
      Produces a new Uni invoking the given function when the current Uni fires an item. The function transforms the received item into a failure that will be fired by the produced Uni. For asynchronous composition, see transformToUni(Function)}.
      Parameters:
      mapper - the mapper function, must not be null, must not return null
      Returns:
      the new Uni
    • failWith

      @CheckReturnValue public Uni<T> failWith(Supplier<? extends Throwable> supplier)
      Produces a new Uni invoking the given supplier when the current Uni fires an item. The supplier produce the received item into a failure that will be fired by the produced Uni.
      Parameters:
      supplier - the supplier to produce the failure, must not be null, must not produce null
      Returns:
      the new Uni
    • castTo

      @CheckReturnValue public <O> Uni<O> castTo(Class<O> target)
      Produces an Uni 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 observed Uni fires null as item. While null 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 observed Uni fies a non-null item. If the item is null, 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 upstream Uni that is either a Publisher<O>, an O[], an Iterable<O> or a Multi<O> and disjoint the items to obtain a Multi<O>.

      For examples, Uni<[A, B, C]> is transformed into Multi<A, B, C>, Uni<[]> is transformed into an empty Multi.

      If the item from the upstream are not instances of Iterable, Flow.Publisher or array, an IllegalArgumentException is propagated downstream.

      If the item is null, an empty Multi 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