Package com.couchbase.client.core
Class Reactor
java.lang.Object
com.couchbase.client.core.Reactor
This class provides utility methods when working with reactor.
- Since:
- 2.0.0
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Sinks.EmitFailureHandler
Constructs a new EmitFailureHandler with the default busy wait duration.static Sinks.EmitFailureHandler
emitFailureHandler
(Duration duration) Constructs a new EmitFailureHandler with a custom busy wait duration.static <T> Flux<T>
shieldFromCancellation
(Flux<T> flux) Returns a new Flux that wraps the given Flux and receives events from it.toFlux
(Supplier<CompletableFuture<C>> input) Helper method to wrap an async call into a reactive one and translate exceptions appropriately.static <T> Mono<T>
toMono
(Supplier<CompletableFuture<T>> input) Helper method to wrap an async call into a reactive one and translate exceptions appropriately.static <T> Mono<T>
wrap
(Request<?> request, CompletableFuture<T> response, boolean propagateCancellation) static <T> Mono<T>
wrap
(CompletableFuture<T> response, Runnable cancellationTask) Converts the given future into a mono.
-
Field Details
-
DEFAULT_EMIT_BUSY_DURATION
-
-
Method Details
-
wrap
public static <T> Mono<T> wrap(Request<?> request, CompletableFuture<T> response, boolean propagateCancellation) - Parameters:
request
- the request to wrap.response
- the full response to wrap, might not be the same as in the request.propagateCancellation
- if a cancelled/unsubscribed mono should also cancel the request.- Returns:
- the mono that wraps the request.
-
wrap
Converts the given future into a mono. Runs the given cancellation task when the mono is cancelled. -
toMono
Helper method to wrap an async call into a reactive one and translate exceptions appropriately.- Parameters:
input
- a supplier that will be called on every subscription.- Returns:
- a mono that invokes the given supplier on each subscription.
-
toFlux
Helper method to wrap an async call into a reactive one and translate exceptions appropriately.- Parameters:
input
- a supplier that will be called on every subscription.- Returns:
- a flux that invokes the given supplier on each subscription.
-
emitFailureHandler
Constructs a new EmitFailureHandler with the default busy wait duration.- Returns:
- a new emit failure handler, busy looping for
DEFAULT_EMIT_BUSY_DURATION
.
-
emitFailureHandler
Constructs a new EmitFailureHandler with a custom busy wait duration.- Parameters:
duration
- the duration to busy loop until failure.- Returns:
- a new emit failure handler, busy looping for the given duration.
-
shieldFromCancellation
Returns a new Flux that wraps the given Flux and receives events from it. If the returned Flux is cancelled, the cancellation is not propagated to the inner Flux.Useful for cooperative cancellation schemes, where an external flag (typically an
AtomicBoolean
) is set whenever the inner Flux should stop emitting events. The external flag is typically set by aFlux.doOnCancel(java.lang.Runnable)
callback on the returned Flux.This allows the inner Flux to do non-trivial cleanup work before it terminates.
-