Class MultiResource<R,I>
- java.lang.Object
-
- io.smallrye.mutiny.groups.MultiResource<R,I>
-
- Type Parameters:
R- the type of resourceI- the type of item emitted by the resultingMulti
public class MultiResource<R,I> extends java.lang.ObjectAllows configuring a finalizer to close the resource attached to the stream.- See Also:
MultiCreate.resource(Supplier, Function)
-
-
Constructor Summary
Constructors Constructor Description MultiResource(java.util.function.Supplier<? extends R> resourceSupplier, java.util.function.Function<? super R,? extends org.reactivestreams.Publisher<I>> streamSupplier)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Multi<I>withFinalizer(java.util.function.Consumer<? super R> finalizer)Configures a synchronous finalizer.Multi<I>withFinalizer(java.util.function.Function<? super R,Uni<java.lang.Void>> finalizer)Configures an asynchronous finalizer.Multi<I>withFinalizer(java.util.function.Function<? super R,Uni<java.lang.Void>> onCompletion, java.util.function.BiFunction<? super R,? super java.lang.Throwable,Uni<java.lang.Void>> onFailure, java.util.function.Function<? super R,Uni<java.lang.Void>> onCancellation)Configures asynchronous finalizers distinct for each event.
-
-
-
Method Detail
-
withFinalizer
public Multi<I> withFinalizer(java.util.function.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 benull- Returns:
- the multi
-
withFinalizer
public Multi<I> withFinalizer(java.util.function.Function<? super R,Uni<java.lang.Void>> finalizer)
Configures an asynchronous finalizer. The given function is called when the stream completes, fails or when the subscriber cancels. The returnedUniis flattened with the stream meaning that the subscriber gets the events fired by theUni. If theUnicompletes successfully, the subscriber gets thecompletionevent. If theUnifails, the subscriber gets the failure even if the resource stream completed successfully. If theUnifails after a resource stream failure, the subscriber receives aCompositeException. If the subscribers cancels, theUnioutcome 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, aNullPointerExceptionis propagated to the subscriber, unless it has already cancelled.- Parameters:
finalizer- the finalizer, must not benull- Returns:
- the multi
-
withFinalizer
public Multi<I> withFinalizer(java.util.function.Function<? super R,Uni<java.lang.Void>> onCompletion, java.util.function.BiFunction<? super R,? super java.lang.Throwable,Uni<java.lang.Void>> onFailure, java.util.function.Function<? super R,Uni<java.lang.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
Uniis flattened with the stream meaning that the subscriber gets the events fired by theUni. If theUnicompletes successfully, the subscriber gets thecompletionevent. If theUnifails, the subscriber gets the failure even if the resource stream completed successfully. If theUnifails after a resource stream failure, the subscriber receives aCompositeException. If the subscribers cancels, theUnioutcome 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, aNullPointerExceptionis propagated to the subscriber, unless it has already cancelled.- Parameters:
onCompletion- the completion finalizer called when the resource stream completes successfully. Must not benullonFailure- the failure finalizer called when the resource stream propagated a failure. The finalizer is called with the resource and the failure. Must not benullonCancellation- the cancellation finalizer called when the subscribers cancels the subscription. Must not benull.- Returns:
- the multi
-
-