Interface Uni<T>

    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods 
      Modifier and Type Method Description
      default Uni<ItemWithContext<T>> attachContext()
      Materialize the context by attaching it to items using the ItemWithContext wrapper class.
      UniAwait<T> await()
      Awaits (blocking the caller thread) until the item or a failure is emitted by the observed Uni.
      default UniAwait<T> awaitUsing​(Context context)
      Awaits (blocking the caller thread) until the item or a failure is emitted by the observed Uni.
      default Uni<T> call​(java.util.function.Function<? super T,​Uni<?>> function)
      Produces a new Uni invoking the given @{code action} when the item event is received.
      default Uni<T> call​(java.util.function.Supplier<Uni<?>> supplier)
      Produces a new Uni invoking the given @{code action} when the item event is received, but ignoring it.
      default <O> Uni<O> chain​(java.util.function.Function<? super T,​Uni<? extends O>> mapper)
      Once the observed Uni emits an item, execute the given mapper.
      default <O> Uni<O> chain​(java.util.function.Supplier<Uni<? extends O>> supplier)
      Once the observed Uni emits an item, execute the given supplier.
      static UniCombine combine()
      Creates a new Uni combining several others unis such as all or any.
      UniConvert<T> convert()
      Converts an Uni to other types such as CompletionStage
      static UniCreate createFrom()
      Creates a new Uni from various sources such as CompletionStage, UniEmitter, direct values, Exception...
      Uni<T> emitOn​(java.util.concurrent.Executor executor)
      Produces a new Uni invoking the UniSubscriber.onItem(Object) and UniSubscriber.onFailure(Throwable) on the supplied Executor.
      default Uni<T> eventually​(java.lang.Runnable action)
      Execute an action after an item or a failure has been emitted.
      default <O> Uni<T> eventually​(java.util.function.Supplier<Uni<? extends O>> supplier)
      When this Uni emits an item or a failure, invoke a Uni supplier then invoke the supplied Uni.
      default <O> Uni<O> flatMap​(java.util.function.Function<? super T,​Uni<? extends O>> mapper)
      Transforms the received item asynchronously, forwarding the events emitted by another Uni produced by the given mapper.
      UniIfNoItem<T> ifNoItem()
      Produces a Uni reacting when a no item event is fired by the upstream uni during the specified time period.
      default Uni<T> invoke​(java.lang.Runnable callback)
      Produces a new Uni invoking the given callback when the item event is fired, but ignoring it.
      default Uni<T> invoke​(java.util.function.Consumer<? super T> callback)
      Produces a new Uni invoking the given callback when the item event is fired.
      static UniJoin join()
      Join the results from multiple Uni (e.g., collect all values, pick the first to respond, etc).
      Uni<T> log()
      Log events (onSubscribe, onItem, ...) as they come from the upstream or the subscriber, and derives the identifier from the upstream operator class "simple name".
      Uni<T> log​(java.lang.String identifier)
      Log events (onSubscribe, onItem, ...) as they come from the upstream or the subscriber.
      default <O> Uni<O> map​(java.util.function.Function<? super T,​? extends O> mapper)
      Transforms the item (potentially null) emitted by this Uni by applying a (synchronous) function to it.
      UniMemoize<T> memoize()
      Configure memoization of the Uni item or failure.
      UniOnCancel<T> onCancellation()
      Configures actions to be performed when the subscriber cancels the subscription.
      UniOnFailure<T> onFailure()
      Like onFailure(Predicate) but applied to all failures fired by the upstream uni.
      UniOnFailure<T> onFailure​(java.lang.Class<? extends java.lang.Throwable> typeOfFailure)
      Configures a type of failure filtering the failures on which the behavior (specified with the returned UniOnFailure) is applied.
      UniOnFailure<T> onFailure​(java.util.function.Predicate<? super java.lang.Throwable> predicate)
      Configures a predicate filtering the failures on which the behavior (specified with the returned UniOnFailure) is applied.
      UniOnItem<T> onItem()
      Configures the action to execute when the observed Uni emits the item (potentially null).
      UniOnItemOrFailure<T> onItemOrFailure()
      Configures the action to execute when the observed Uni emits either an item (potentially null)) or a failure.
      UniOnSubscribe<T> onSubscribe()
      Deprecated.
      use onSubscription() instead
      UniOnSubscribe<T> onSubscription()
      Configures the action to execute when the observed Uni sends a UniSubscription.
      UniOnTerminate<T> onTermination()
      Configures actions to be performed on termination, that is, on item, on failure, or when the subscriber cancels the subscription.
      default <R> Uni<R> plug​(java.util.function.Function<Uni<T>,​Uni<R>> operatorProvider)
      Plug a user-defined operator that does not belong to the existing Mutiny API.
      UniRepeat<T> repeat()
      Allows configuring repeating behavior.
      default Uni<T> replaceIfNullWith​(java.util.function.Supplier<T> supplier)
      When this Uni emits null, replace with the value provided by the given Supplier.
      default Uni<T> replaceIfNullWith​(T value)
      When this Uni emits null, replace with the provided value.
      default <O> Uni<O> replaceWith​(Uni<O> uni)
      Ignore the item emitted by this Uni and replace it with another value using a Uni.
      default <O> Uni<O> replaceWith​(java.util.function.Supplier<O> supplier)
      Ignore the item emitted by this Uni and replace it with another value using a Supplier.
      default <O> Uni<O> replaceWith​(O item)
      Ignore the item emitted by this Uni and replace it with another value.
      default Uni<T> replaceWithNull()
      Ignore the item emitted by this Uni and replace it with null.
      default Uni<java.lang.Void> replaceWithVoid()
      Ignore the item emitted by this Uni and replace it with null and type Void.
      Uni<T> runSubscriptionOn​(java.util.concurrent.Executor executor)
      When a subscriber subscribes to this Uni, executes the subscription to the upstream Uni on a thread from the given executor.
      default <O> O stage​(java.util.function.Function<Uni<T>,​O> stage)
      Allows structuring the pipeline by creating a logic separation:
      UniSubscribe<T> subscribe()
      Requests the Uni to start resolving the item and allows configuring how the signals are propagated (using a UniSubscriber, callbacks, or a CompletionStage.
      default java.util.concurrent.CompletableFuture<T> subscribeAsCompletionStage()
      default java.util.concurrent.CompletableFuture<T> subscribeAsCompletionStage​(Context context)
      Multi<T> toMulti()
      Creates an instance of Multi from this Uni.
      default <R> Uni<R> withContext​(java.util.function.BiFunction<Uni<T>,​Context,​Uni<R>> builder)
      Materialize the subscriber Context for a sub-pipeline.
    • Method Detail

      • createFrom

        @CheckReturnValue
        static UniCreate createFrom()
        Creates a new Uni from various sources such as CompletionStage, UniEmitter, direct values, Exception...

        Examples:

         
         Uni.createFrom().item(1); // Emit 1 at subscription time
         Uni.createFrom().item(() -> x); // Emit x at subscription time, the supplier is invoked for each subscription
         Uni.createFrom().completionStage(cs); // Emit the item from this completion stage
         Uni.createFrom().completionStage(() -> cs); // Emit the item from this completion stage, the stage is not created before subscription
         Uni.createFrom().failure(exception); // Emit the failure at subscription time
         Uni.createFrom().deferred(() -> Uni.from().value(x)); // Defer the uni creation until subscription. Each subscription can produce a different uni
         Uni.createFrom().item(null); // Emit null at subscription time
         Uni.createFrom().nothing(); // Create a Uni not emitting any signal
         Uni.createFrom().publisher(publisher); // Create a Uni from a Reactive Streams Publisher
         
         
        Returns:
        the factory used to create Uni instances.
        See Also:
        UniCreate
      • stage

        @CheckReturnValue
        default <O> O stage​(java.util.function.Function<Uni<T>,​O> stage)
        Allows structuring the pipeline by creating a logic separation:
         
             Uni uni = upstream
              .stage(u -> { ...})
              .stage(u -> { ...})
              .stage(u -> { ...})
         
         

        With `stage` you can structure and chain groups of processing.

        Type Parameters:
        O - the outcome type
        Parameters:
        stage - the function receiving this Uni as parameter and producing the outcome (can be a Uni or something else), must not be null.
        Returns:
        the outcome of the function.
      • combine

        @CheckReturnValue
        static UniCombine combine()
        Creates a new Uni combining several others unis such as all or any.
        Returns:
        the factory use to combine the uni instances
      • subscribe

        @CheckReturnValue
        UniSubscribe<T> subscribe()
        Requests the Uni to start resolving the item and allows configuring how the signals are propagated (using a UniSubscriber, callbacks, or a CompletionStage. Unlike await(), this method configures non-blocking retrieval of the item and failure.

        Examples:

         
             Uni<String> uni = ...;
        
            Subscription sub = uni.subscribe().with( // The return subscription can be used to cancel the operation
                      item -> {},           // Callback calls on item
                      failure -> {}           // Callback calls on failure
            );
        
            UniSubscriber<String> myUniSubscriber = ...
            uni.subscribe().withSubscriber(myUniSubscriber); // Subscribes to the Uni with the passed subscriber
        
            CompletableFuture future = uni.subscribe().asCompletableFuture(); // Get a CompletionStage receiving the item or failure
            // Cancelling the returned future cancels the subscription.
         
         
        Returns:
        the object to configure the subscription.
        See Also:
        uni.await() for waiting (blocking the caller thread) until the resolution of the observed Uni.
      • subscribeAsCompletionStage

        @CheckReturnValue
        default java.util.concurrent.CompletableFuture<T> subscribeAsCompletionStage()
        Returns:
        the completion stage receiving the items emitted by this Uni
      • subscribeAsCompletionStage

        @CheckReturnValue
        @Experimental("Context support is a new experimental API introduced in Mutiny 1.3.0")
        default java.util.concurrent.CompletableFuture<T> subscribeAsCompletionStage​(Context context)
        Parameters:
        context - the context, cannot null
        Returns:
        the completion stage receiving the items emitted by this Uni
      • await

        @CheckReturnValue
        UniAwait<T> await()
        Awaits (blocking the caller thread) until the item or a failure is emitted by the observed Uni. If the observed uni fails, the failure is thrown. In the case of a checked exception, the exception is wrapped into a CompletionException.

        Examples:

         
         Uni<T> uni = ...;
         T res = uni.await().indefinitely(); // Await indefinitely until it get the item.
         T res = uni.await().atMost(Duration.ofMillis(1000)); // Awaits at most 1s. After that, a TimeoutException is thrown
         Optional<T> res = uni.await().asOptional().indefinitely(); // Retrieves the item as an Optional, empty if the item is null
         
         
        Returns:
        the object to configure the retrieval.
      • awaitUsing

        @CheckReturnValue
        @Experimental("Context support is a new experimental API introduced in Mutiny 1.3.0")
        default UniAwait<T> awaitUsing​(Context context)
        Awaits (blocking the caller thread) until the item or a failure is emitted by the observed Uni. If the observed uni fails, the failure is thrown. In the case of a checked exception, the exception is wrapped into a CompletionException.

        Examples:

         
         Uni<T> uni = ...;
         T res = uni.awaitUsing(context).indefinitely(); // Await indefinitely until it get the item.
         T res = uni.awaitUsing(context).atMost(Duration.ofMillis(1000)); // Awaits at most 1s. After that, a TimeoutException is thrown
         Optional<T> res = uni.awaitUsing(context).asOptional().indefinitely(); // Retrieves the item as an Optional, empty if the item is null
         
         
        Parameters:
        context - the context, cannot be null
        Returns:
        the object to configure the retrieval.
      • onItem

        @CheckReturnValue
        UniOnItem<T> onItem()
        Configures the action to execute when the observed Uni emits the item (potentially null).

        Examples:

         
         Uni<T> uni = ...;
         uni.onItem().transform(x -> ...); // Transform the item into another item (~ map)
         uni.onItem().transformToUni(x -> ...); // Transform the item into a Uni (~ flatMap)
         
         
        Returns:
        the object to configure the action to execute when an item is emitted
      • onSubscribe

        @Deprecated
        @CheckReturnValue
        UniOnSubscribe<T> onSubscribe()
        Deprecated.
        use onSubscription() instead
        Configures the action to execute when the observed Uni sends a UniSubscription. The downstream don't have a subscription yet. It will be passed once the configured action completes.

        Example:

         
         uni.onSubscribe().invoke(sub -> System.out.println("subscribed"));
         // Delay the subscription by 1 second (or until an asynchronous action completes)
         uni.onSubscribe().call(sub -> Uni.createFrom(1).onItem().delayIt().by(Duration.ofSecond(1)));
         
         
        Returns:
        the object to configure the action to execution on subscription.
      • onSubscription

        @CheckReturnValue
        UniOnSubscribe<T> onSubscription()
        Configures the action to execute when the observed Uni sends a UniSubscription. The downstream does not have a subscription yet. It will be passed once the configured action completes.

        Example:

         
         uni.onSubscription().invoke(sub -> System.out.println("subscribed"));
         // Delay the subscription by 1 second (or until an asynchronous action completes)
         uni.onSubscription().call(sub -> Uni.createFrom(1).onItem().delayIt().by(Duration.ofSecond(1)));
         
         
        Returns:
        the object to configure the action to execution on subscription.
      • onItemOrFailure

        @CheckReturnValue
        UniOnItemOrFailure<T> onItemOrFailure()
        Configures the action to execute when the observed Uni emits either an item (potentially null)) or a failure. Unlike onItem() and onFailure() the action would handle both cases in on "go".
        Returns:
        the object to configure the action to execute when an item is emitted or when a failure is propagated.
      • onFailure

        @CheckReturnValue
        UniOnFailure<T> onFailure()
        Like onFailure(Predicate) but applied to all failures fired by the upstream uni. It allows configuring the on failure behavior (recovery, retry...).
        Returns:
        a UniOnFailure on which you can specify the on failure action
      • onFailure

        @CheckReturnValue
        UniOnFailure<T> onFailure​(java.util.function.Predicate<? super java.lang.Throwable> predicate)
        Configures a predicate filtering the failures on which the behavior (specified with the returned UniOnFailure) is applied.

        For instance, to only when an IOException is fired as failure you can use: uni.onFailure(IOException.class).recoverWithItem("hello")

        The fallback value (hello) will only be used if the upstream uni fire a failure of type IOException.

        Parameters:
        predicate - the predicate, null means applied to all failures
        Returns:
        a UniOnFailure configured with the given predicate on which you can specify the on failure action
      • onFailure

        @CheckReturnValue
        UniOnFailure<T> onFailure​(java.lang.Class<? extends java.lang.Throwable> typeOfFailure)
        Configures a type of failure filtering the failures on which the behavior (specified with the returned UniOnFailure) is applied.

        For instance, to only when an IOException is fired as failure you can use: uni.onFailure(IOException.class).recoverWithItem("hello")

        The fallback value (hello) will only be used if the upstream uni fire a failure of type IOException.

        Parameters:
        typeOfFailure - the class of exception, must not be null
        Returns:
        a UniOnFailure configured with the given predicate on which you can specify the on failure action
      • ifNoItem

        @CheckReturnValue
        UniIfNoItem<T> ifNoItem()
        Produces a Uni reacting when a no item event is fired by the upstream uni during the specified time period.

        This Uni detects if this Uni does not emit an item before the configured timeout.

        Examples: uni.ifNoItem().after(Duration.ofMillis(1000).fail() // Propagate a TimeOutException uni.ifNoItem().after(Duration.ofMillis(1000).recoverWithValue("fallback") // Inject a fallback item on timeout uni.ifNoItem().after(Duration.ofMillis(1000).on(myExecutor)... // Configure the executor calling on timeout actions uni.ifNoItem().after(Duration.ofMillis(1000).retry().atMost(5) // Retry five times

        Returns:
        the on timeout group
      • emitOn

        @CheckReturnValue
        Uni<T> emitOn​(java.util.concurrent.Executor executor)
        Produces a new Uni invoking the UniSubscriber.onItem(Object) and UniSubscriber.onFailure(Throwable) on the supplied Executor.

        Instead of receiving the item event on the thread firing the event, this method influences the threading context to switch to a thread from the given executor.

        Parameters:
        executor - the executor to use, must not be null
        Returns:
        a new Uni
      • runSubscriptionOn

        @CheckReturnValue
        Uni<T> runSubscriptionOn​(java.util.concurrent.Executor executor)
        When a subscriber subscribes to this Uni, executes the subscription to the upstream Uni on a thread from the given executor. As a result, the UniSubscriber.onSubscribe(UniSubscription) method will be called on this thread (except mentioned otherwise)
        Parameters:
        executor - the executor to use, must not be null
        Returns:
        a new Uni
      • memoize

        @CheckReturnValue
        UniMemoize<T> memoize()
        Configure memoization of the Uni item or failure.
        API Note:
        This is an experimental API
        Returns:
        the object to configure memoization
      • map

        @CheckReturnValue
        default <O> Uni<O> map​(java.util.function.Function<? super T,​? extends O> mapper)
        Transforms the item (potentially null) emitted by this Uni by applying a (synchronous) function to it. This method is equivalent to uni.onItem().transform(x -> ...) For asynchronous composition, look at flatMap.
        Type Parameters:
        O - the output type
        Parameters:
        mapper - the mapper function, must not be null
        Returns:
        a new Uni computing an item of type <O>.
      • invoke

        @CheckReturnValue
        default Uni<T> invoke​(java.util.function.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.

        This method is a shortcut on UniOnItem.invoke(Consumer)

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

        @CheckReturnValue
        default Uni<T> invoke​(java.lang.Runnable callback)
        Produces a new Uni invoking the given callback when the item event is fired, but ignoring it.

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

        This method is a shortcut on UniOnItem.invoke(Consumer)

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

        @CheckReturnValue
        default Uni<T> call​(java.util.function.Function<? super T,​Uni<?>> function)
        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. If the callback throws an exception, this exception is propagated downstream as failure.

        This method is a shortcut on UniOnItem.call(Function)

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

        @CheckReturnValue
        default Uni<T> call​(java.util.function.Supplier<Uni<?>> supplier)
        Produces a new Uni invoking the given @{code action} when the item event is received, but 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. If the callback throws an exception, this exception is propagated downstream as failure.

        This method is a shortcut on UniOnItem.call(Function)

        Parameters:
        supplier - the supplier taking the item and returning a Uni, must not be null, must not return null
        Returns:
        the new Uni
      • flatMap

        @CheckReturnValue
        default <O> Uni<O> flatMap​(java.util.function.Function<? super T,​Uni<? extends O>> 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. This method is a shortcut on UniOnItem.transformToUni(Function) onItem().transformToUni(mapper)}.

        Type Parameters:
        O - 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.
      • chain

        @CheckReturnValue
        default <O> Uni<O> chain​(java.util.function.Function<? super T,​Uni<? extends O>> mapper)
        Once the observed Uni emits an item, execute the given mapper. This mapper produces another Uni. The downstream receives the events emitted by this produced Uni.

        This operation allows chaining asynchronous operations: when the upstream completes with an item, run the mapper and emits the item (or failure) sent by the produced Uni:

         Uni<Session> uni = getSomeSession();
         return uni.chain(session -> session.persist(fruit))
                 .chain(session -> session.flush())
                 .map(x -> Response.ok(fruit).status(201).build());
         

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

        This operation is generally named flatMap. This method is a shortcut for onItem().transformToUni(mapper).

        Type Parameters:
        O - 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.
        See Also:
        chain(Supplier)
      • chain

        @CheckReturnValue
        default <O> Uni<O> chain​(java.util.function.Supplier<Uni<? extends O>> supplier)
        Once the observed Uni emits an item, execute the given supplier. This supplier produces another Uni. The downstream receives the events emitted by this produced Uni.

        This operation allows chaining asynchronous operations: when the upstream completes with an item, run the supplier and emits the item (or failure) sent by the produced Uni:

         Uni<Session> uni = getSomeSession();
         return uni.chain(session -> session.persist(fruit))
                 .chain(session -> session.flush())
                 .chain(() -> server.close());
         

        The supplier ignores the item event of the current Uni and produces an Uni, possibly using another type of item (O). The events fired by produced Uni are forwarded to the Uni returned by this method.

        This method is a shortcut for UniOnItem.transformToUni(Function) onItem().transformToUni(ignored -> supplier.get()).

        Type Parameters:
        O - the type of item
        Parameters:
        supplier - the supplier 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.
        See Also:
        chain(Supplier)
      • eventually

        @CheckReturnValue
        default Uni<T> eventually​(java.lang.Runnable action)
        Execute an action after an item or a failure has been emitted. This is equivalent to a finally block in Java.
         
         String id = ...;
         Session session = getSomeSession();
         session.find(Fruit.class, id)
                .chain(fruit -> session.remove(fruit)
                .then(() -> session.flush())
                .eventually(() -> session.close());
         
         

        This method is a shortcut for UniOnItemOrFailure.invoke(BiConsumer): onItemOrFailure().invoke((item, err) -> action.run())

        Parameters:
        action - an action to perform, must not be null.
        Returns:
        a new Uni that emits events once the action has completed.
        See Also:
        onItemOrFailure()
      • eventually

        @CheckReturnValue
        default <O> Uni<T> eventually​(java.util.function.Supplier<Uni<? extends O>> supplier)
        When this Uni emits an item or a failure, invoke a Uni supplier then invoke the supplied Uni. When the supplied Uni emits an item then it is ignored, and when it emits a failure it is reported.

        This is equivalent to a finally block in Java.

         
         String id = ...;
         Session session = getSomeSession();
         session.find(Fruit.class, id)
                .chain(fruit -> session.remove(fruit)
                .eventually(() -> session.close());
         
         

        This method is a shortcut for UniOnItemOrFailure.call(BiFunction): onItemOrFailure().call((item, err) -> supplier.get())

        Type Parameters:
        O - the type of the item
        Parameters:
        supplier - a Uni supplier, cannot be null and cannot return null.
        Returns:
        a new Uni that emits events once the supplied Uni emits an item or a failure.
        See Also:
        onItemOrFailure()
      • convert

        @CheckReturnValue
        UniConvert<T> convert()
        Converts an Uni to other types such as CompletionStage

        Examples:

         
         uni.convert().toCompletionStage(); // Convert to CompletionStage using convenience method
         uni.convert().with(BuiltinConverters.toCompletionStage()); // Convert to CompletionStage using BuiltInConverters
         uni.convert().with(uni -> x); // Convert with a custom lambda converter
         
         
        Returns:
        the object to convert an Uni instance
        See Also:
        UniConvert
      • toMulti

        @CheckReturnValue
        Multi<T> toMulti()
        Creates an instance of Multi from this Uni.

        When a subscriber subscribes to the returned Multi and request an item, it subscribes to this Uni and the events from this Uni are propagated to the Multi:

        • if this Uni emits a non-null item - this item is propagated to the Multi and followed with the completion event
        • if this Uni emits a null item - the Multi fires the completion event
        • if this Uni emits a failure, this failure event is propagated by the Multi

        It's important to note that the subscription to this Uni happens when the subscriber to the produced Multi requests items, and not at subscription time.

        Returns:
        the produced Multi, never null
      • repeat

        @CheckReturnValue
        UniRepeat<T> repeat()
        Allows configuring repeating behavior. Repeating allow transforming a Uni into a Multi either a specific amount of times or indefinitely. Each time, a new subscription is attempted on the Uni. Cancelling the subscription stops the repeating behavior.
        Returns:
        the object to configure the repeating behavior.
      • onTermination

        @CheckReturnValue
        UniOnTerminate<T> onTermination()
        Configures actions to be performed on termination, that is, on item, on failure, or when the subscriber cancels the subscription.
        Returns:
        the object to configure the termination actions.
      • onCancellation

        @CheckReturnValue
        UniOnCancel<T> onCancellation()
        Configures actions to be performed when the subscriber cancels the subscription.
        Returns:
        the object to configure the cancellation actions.
      • plug

        @CheckReturnValue
        default <R> Uni<R> plug​(java.util.function.Function<Uni<T>,​Uni<R>> operatorProvider)
        Plug a user-defined operator that does not belong to the existing Mutiny API.
        Type Parameters:
        R - the output type
        Parameters:
        operatorProvider - a function to create and bind a new operator instance, taking this Uni as a parameter and returning a new Uni. Must neither be null nor return null.
        Returns:
        the new Uni
      • replaceWith

        @CheckReturnValue
        default <O> Uni<O> replaceWith​(O item)
        Ignore the item emitted by this Uni and replace it with another value.

        This is a shortcut for uni.onItem().transform(ignore -> item).

        Type Parameters:
        O - the output type
        Parameters:
        item - the replacement value
        Returns:
        the new Uni
      • replaceWith

        @CheckReturnValue
        default <O> Uni<O> replaceWith​(java.util.function.Supplier<O> supplier)
        Ignore the item emitted by this Uni and replace it with another value using a Supplier.

        This is a shortcut for uni.onItem().transform(ignore -> supplier.get()).

        Type Parameters:
        O - the output type
        Parameters:
        supplier - the replacement value supplier
        Returns:
        the new Uni
      • replaceWith

        @CheckReturnValue
        default <O> Uni<O> replaceWith​(Uni<O> uni)
        Ignore the item emitted by this Uni and replace it with another value using a Uni.

        This is a shortcut for uni.onItem().transformToUni(ignore -> uni).

        Type Parameters:
        O - the output type
        Parameters:
        uni - the replacement value Uni
        Returns:
        the new Uni
      • replaceWithNull

        @CheckReturnValue
        default Uni<T> replaceWithNull()
        Ignore the item emitted by this Uni and replace it with null.

        This is a shortcut for uni.onItem().transform(ignore -> null).

        Returns:
        the new Uni
      • replaceWithVoid

        @CheckReturnValue
        default Uni<java.lang.Void> replaceWithVoid()
        Ignore the item emitted by this Uni and replace it with null and type Void.

        This method is in effect similar to replaceWithNull(), except that it returns a Uni<Void> instead of a Uni<T>.

        This is a shortcut for uni.onItem().transform(ignored -> null).

        Returns:
        the new Uni
      • replaceIfNullWith

        @CheckReturnValue
        default Uni<T> replaceIfNullWith​(java.util.function.Supplier<T> supplier)
        When this Uni emits null, replace with the value provided by the given Supplier.

        This is a shortcut for uni.onItem().ifNull().continueWith(supplier)

        Parameters:
        supplier - the supplier
        Returns:
        the new Uni
      • replaceIfNullWith

        @CheckReturnValue
        default Uni<T> replaceIfNullWith​(T value)
        When this Uni emits null, replace with the provided value.

        This is a shortcut for uni.onItem().ifNull().continueWith(value)

        Parameters:
        value - the value
        Returns:
        the new Uni
      • log

        @CheckReturnValue
        Uni<T> log​(java.lang.String identifier)
        Log events (onSubscribe, onItem, ...) as they come from the upstream or the subscriber.

        Events will be logged as long as the Uni hasn't been cancelled or terminated. Logging is framework-agnostic and can be configured in the Infrastructure class.

        Parameters:
        identifier - an identifier of this operator to be used in log events
        Returns:
        a new Uni
        See Also:
        Infrastructure.setOperatorLogger(Infrastructure.OperatorLogger)
      • join

        @Experimental("New API based on observations that Uni.combine() is often used with homogeneous types, and combination often just a mapping to a collection.")
        @CheckReturnValue
        static UniJoin join()
        Join the results from multiple Uni (e.g., collect all values, pick the first to respond, etc).

        Here is an example where several Uni are joined, and result in a Uni<List<Number>>:

         Uni<Number> a = Uni.createFrom().item(1);
         Uni<Number> b = Uni.createFrom().item(2L);
         Uni<Number> c = Uni.createFrom().item(3);
        
         Uni<List<Number>> uni = Uni.join().all(a, b, c).andCollectFailures();
         

        The list of Unis must not be empty, as in that case, no event will be sent.

        Returns:
        the object to configure the join behavior.
      • withContext

        @Experimental("Context support is a new experimental API introduced in Mutiny 1.3.0")
        @CheckReturnValue
        default <R> Uni<R> withContext​(java.util.function.BiFunction<Uni<T>,​Context,​Uni<R>> builder)
        Materialize the subscriber Context for a sub-pipeline.

        The provided function takes this Uni and the Context as parameters, and returns a Uni to build the sub-pipeline, as in:

         
         someUni.withContext((uni, ctx) -> uni.onItem().transform(n -> n + "::" + ctx.getOrElse("foo", () -> "yolo")));
         
         

        Note that the builder function is called at subscription time, so it cannot see context updates from upstream operators yet.

        Type Parameters:
        R - the resulting Uni type
        Parameters:
        builder - the function that builds the sub-pipeline from this Uni and the Context, must not be null, must not return null.
        Returns:
        the resulting Uni
      • attachContext

        @Experimental("Context support is a new experimental API introduced in Mutiny 1.3.0")
        @CheckReturnValue
        default Uni<ItemWithContext<T>> attachContext()
        Materialize the context by attaching it to items using the ItemWithContext wrapper class.

        This is a shortcut for:

         
         someUni.withContext((uni, ctx) -> uni.onItem().transform(item -> new ItemWithContext<>(ctx, item)));
         
         
        Returns:
        the resulting Uni
        See Also:
        withContext(BiFunction)