Class UniSubscribe<T>

java.lang.Object
io.smallrye.mutiny.groups.UniSubscribe<T>
Type Parameters:
T - the type of item

public class UniSubscribe<T> extends Object
Allow subscribing to a Uni to be notified of the different events coming from upstream. Two kind of events can be received:
  • item - the item of the Uni, can be null
  • failure - the failure propagated by the Uni
  • Constructor Details

    • UniSubscribe

      public UniSubscribe(AbstractUni<T> upstream)
  • Method Details

    • withSubscriber

      public <S extends UniSubscriber<? super T>> S withSubscriber(S subscriber)
      Requests the Uni to start computing the item.

      This is a "factory method" and can be called multiple times, each time starting a new UniSubscription. Each UniSubscription will work for only a single UniSubscriber. A UniSubscriber should only subscribe once to a single Uni.

      If the Uni rejects the subscription attempt or otherwise fails it will fire a failure event receiving by UniSubscriber.onFailure(Throwable).

      Type Parameters:
      S - the type of subscriber returned
      Parameters:
      subscriber - the subscriber, must not be null
      Returns:
      the passed subscriber
    • withSerializedSubscriber

      public <S extends UniSubscriber<? super T>> S withSerializedSubscriber(S subscriber)
      Requests the Uni to start computing the item, but wraps the provided subscriber in a UniSerializedSubscriber instance that enforces correct events ordering.

      This is a "factory method" and can be called multiple times, each time starting a new UniSubscription. Each UniSubscription will work for only a single UniSubscriber. A UniSubscriber should only subscribe once to a single Uni.

      If the Uni rejects the subscription attempt or otherwise fails it will fire a failure event receiving by UniSubscriber.onFailure(Throwable).

      Type Parameters:
      S - the type of subscriber returned
      Parameters:
      subscriber - the subscriber, must not be null
      Returns:
      the passed subscriber
    • with

      public Cancellable with(Consumer<? super T> onItemCallback, Consumer<? super Throwable> onFailureCallback)
      Like withSubscriber(UniSubscriber) with creating an artificial UniSubscriber calling the onItem and onFailure callbacks when the events are received.

      Unlike withSubscriber(UniSubscriber), this method returns the subscription that can be used to cancel the subscription.

      Parameters:
      onItemCallback - callback invoked when the an item event is received, potentially called with null is received. The callback must not be null
      onFailureCallback - callback invoked when a failure event is received, must not be null
      Returns:
      an object to cancel the computation
    • with

      public Cancellable with(Context context, Consumer<? super T> onItemCallback, Consumer<? super Throwable> onFailureCallback)
      Like withSubscriber(UniSubscriber) with creating an artificial UniSubscriber calling the onItem and onFailure callbacks when the events are received.

      Unlike withSubscriber(UniSubscriber), this method returns the subscription that can be used to cancel the subscription.

      Parameters:
      context - the context, must not be null
      onItemCallback - callback invoked when the an item event is received, potentially called with null is received. The callback must not be null
      onFailureCallback - callback invoked when a failure event is received, must not be null
      Returns:
      an object to cancel the computation
    • with

      public Cancellable with(Context context, Consumer<? super T> onItemCallback)
      Like withSubscriber(UniSubscriber) with creating an artificial UniSubscriber calling the onItem when the item is received.

      Unlike withSubscriber(UniSubscriber), this method returns the subscription that can be used to cancel the subscription.

      Unlike with(Consumer, Consumer), this method does not handle failure, and the failure event is dropped.

      Parameters:
      context - the context, must not be null
      onItemCallback - callback invoked when the an item event is received, potentially called with null is received. The callback must not be null
      Returns:
      an object to cancel the computation
    • with

      public Cancellable with(Consumer<? super T> onItemCallback)
      Like withSubscriber(UniSubscriber) with creating an artificial UniSubscriber calling the onItem when the item is received.

      Unlike withSubscriber(UniSubscriber), this method returns the subscription that can be used to cancel the subscription.

      Unlike with(Consumer, Consumer), this method does not handle failure, and the failure event is dropped.

      Parameters:
      onItemCallback - callback invoked when the an item event is received, potentially called with null is received. The callback must not be null
      Returns:
      an object to cancel the computation
    • asCompletionStage

      public CompletableFuture<T> asCompletionStage()
      Like withSubscriber(UniSubscriber) but provides a CompletableFuture to retrieve the completed item (potentially null) and allow chaining operations.
      Returns:
      a CompletableFuture to retrieve the item and chain operations on the resolved item or failure. The returned CompletableFuture can also be used to cancel the computation.
    • asCompletionStage

      public CompletableFuture<T> asCompletionStage(Context context)
      Like withSubscriber(UniSubscriber) but provides a CompletableFuture to retrieve the completed item (potentially null) and allow chaining operations.
      Parameters:
      context - the context, must not be null
      Returns:
      a CompletableFuture to retrieve the item and chain operations on the resolved item or failure. The returned CompletableFuture can also be used to cancel the computation.