reactor-core/src/main/java/reactor/core/publisher/Mono.java
public static <T, D> Mono<T> usingWhen(Publisher<D> resourceSupplier,
			Function<? super D, ? extends Mono<? extends T>> resourceClosure,
			Function<? super D, ? extends Publisher<?>> asyncComplete,
			Function<? super D, ? extends Publisher<?>> asyncError) {
		return onAssembly(new MonoUsingWhen<>(resourceSupplier, resourceClosure,
				asyncComplete, asyncError, null));
	}
public static <T, D> Mono<T> usingWhen(Publisher<D> resourceSupplier,
			Function<? super D, ? extends Mono<? extends T>> resourceClosure,
			Function<? super D, ? extends Publisher<?>> asyncComplete,
			Function<? super D, ? extends Publisher<?>> asyncError) {
		return onAssembly(new MonoUsingWhen<>(resourceSupplier, resourceClosure,
				asyncComplete, asyncError, null));
	}
public static < T , D > Mono < T > usingWhen ( Publisher < D > resourceSupplier , Function < ? super D , ? extends Mono < ? extends T > > resourceClosure , Function < ? super D , ? extends Publisher < ? > > asyncComplete , Function < ? super D , ? extends Publisher < ? > > asyncError ) { return onAssembly ( new MonoUsingWhen <> ( resourceSupplier , resourceClosure , asyncComplete , asyncError , null ) ) ; }
Uses a resource, generated by a {@link Publisher} for each individual {@link Subscriber},
while streaming the values from a {@link Publisher} derived from the same resource.
Whenever the resulting sequence terminates, the relevant {@link Function} generates
a "cleanup" {@link Publisher} that is invoked but doesn't change the content of the
main sequence. Instead it just defers the termination (unless it errors, in which case
the error suppresses the original termination signal).
<p>
<img class="marble" src="doc-files/marbles/usingWhenSuccessForMono.svg" alt="">
<p>
Individual cleanups can also be associated with mono cancellation and
error terminations:
<p>
<img class="marble" src="doc-files/marbles/usingWhenFailureForMono.svg" alt="">
<p>
Note that if the resource supplying {@link Publisher} emits more than one resource, the
subsequent resources are dropped ({@link Operators#onNextDropped(Object, Context)}). If
the publisher errors AFTER having emitted one resource, the error is also silently dropped
({@link Operators#onErrorDropped(Throwable, Context)}).
An empty completion or error without at least one onNext signal triggers a short-circuit
of the main sequence with the same terminal signal (no resource is established, no
cleanup is invoked).

@param resourceSupplier a {@link Publisher} that "generates" the resource,
subscribed for each subscription to the main sequence
@param resourceClosure a factory to derive a {@link Publisher} from the supplied resource
@param asyncComplete an asynchronous resource cleanup invoked if the resource closure terminates with onComplete
@param asyncError an asynchronous resource cleanup invoked if the resource closure terminates with onError
@param <T> the type of elements emitted by the resource closure, and thus the main sequence
@param <D> the type of the resource object
@return a new {@link Flux} built around a "transactional" resource, with several
termination path triggering asynchronous cleanup sequences
@see #usingWhen(Publisher, Function, Function, Function, Function)
Uses a resource generated by a { @link Publisher } for each individual { @link Subscriber } while streaming the values from a { @link Publisher } derived from the same resource . Whenever the resulting sequence terminates the relevant { @link Function } generates a cleanup { @link Publisher } that is invoked but doesn t change the content of the main sequence . Instead it just defers the termination ( unless it errors in which case the error suppresses the original termination signal ) . <p > <img class = marble src = doc - files / marbles / usingWhenSuccessForMono . svg alt = > <p > Individual cleanups can also be associated with mono cancellation and error terminations : <p > <img class = marble src = doc - files / marbles / usingWhenFailureForMono . svg alt = > <p > Note that if the resource supplying { @link Publisher } emits more than one resource the subsequent resources are dropped ( { @link Operators#onNextDropped ( Object Context ) } ) . If the publisher errors AFTER having emitted one resource the error is also silently dropped ( { @link Operators#onErrorDropped ( Throwable Context ) } ) . An empty completion or error without at least one onNext signal triggers a short - circuit of the main sequence with the same terminal signal ( no resource is established no cleanup is invoked ) .