Class MultiResource<R,I>

java.lang.Object
io.smallrye.mutiny.groups.MultiResource<R,I>
Type Parameters:
R - the type of resource
I - the type of item emitted by the resulting Multi

public class MultiResource<R,I> extends Object
Allows configuring a finalizer to close the resource attached to the stream.
See Also:
  • Constructor Details

  • Method Details

    • withFinalizer

      @CheckReturnValue public Multi<I> withFinalizer(Consumer<? super R> finalizer)
      Configures a synchronous finalizer. The given function is called when the stream completes, fails or when the subscriber cancels. If the finalizer throws an exception, this exception is propagated to the subscriber, unless it has already cancelled.
      Parameters:
      finalizer - the finalizer, must not be null
      Returns:
      the multi
    • withFinalizer

      @CheckReturnValue public Multi<I> withFinalizer(Function<? super R,Uni<Void>> finalizer)
      Configures an asynchronous finalizer. The given function is called when the stream completes, fails or when the subscriber cancels. The returned Uni is flattened with the stream meaning that the subscriber gets the events fired by the Uni. If the Uni completes successfully, the subscriber gets the completion event. If the Uni fails, the subscriber gets the failure even if the resource stream completed successfully. If the Uni fails after a resource stream failure, the subscriber receives a CompositeException. If the subscribers cancels, the Uni outcome is ignored.

      If the finalizer throws an exception, this exception is propagated to the subscriber, unless it has already cancelled. If the finalizer returns null, a NullPointerException is propagated to the subscriber, unless it has already cancelled.

      Parameters:
      finalizer - the finalizer, must not be null
      Returns:
      the multi
    • withFinalizer

      @CheckReturnValue public Multi<I> withFinalizer(Function<? super R,Uni<Void>> onCompletion, BiFunction<? super R,? super Throwable,Uni<Void>> onFailure, Function<? super R,Uni<Void>> onCancellation)
      Configures asynchronous finalizers distinct for each event. The given functions are called when the stream completes, fails or when the subscriber cancels.

      The returned Uni is flattened with the stream meaning that the subscriber gets the events fired by the Uni. If the Uni completes successfully, the subscriber gets the completion event. If the Uni fails, the subscriber gets the failure even if the resource stream completed successfully. If the Uni fails after a resource stream failure, the subscriber receives a CompositeException. If the subscribers cancels, the Uni outcome is ignored.

      If a finalizer throws an exception, this exception is propagated to the subscriber, unless it has already cancelled. If a finalizer returns null, a NullPointerException is propagated to the subscriber, unless it has already cancelled.

      Parameters:
      onCompletion - the completion finalizer called when the resource stream completes successfully. Must not be null
      onFailure - the failure finalizer called when the resource stream propagated a failure. The finalizer is called with the resource and the failure. Must not be null
      onCancellation - the cancellation finalizer called when the subscribers cancels the subscription. Must not be null.
      Returns:
      the multi