Package discord4j.common.sinks
Interface EmissionStrategy
A strategy to handle emission failures to a
Sinks.Many
instance.-
Method Summary
Modifier and TypeMethodDescription<T> boolean
emitComplete
(Sinks.Many<T> sink) Try to terminate the givensink
successfully, respecting the semantics ofSinks.Many.tryEmitComplete()
and the failure handling ofSinks.Many.emitComplete(Sinks.EmitFailureHandler)
.<T> boolean
emitError
(Sinks.Many<T> sink, Throwable error) Try to fail the givensink
, respecting the semantics ofSinks.Many.tryEmitError(Throwable)
and the failure handling ofSinks.Many.emitError(Throwable, Sinks.EmitFailureHandler)
.<T> boolean
emitNext
(Sinks.Many<T> sink, T element) Try emitting a givenelement
to the specifiedsink
, respecting the semantics ofSinks.Many.tryEmitNext(Object)
and the failure handling ofSinks.Many.emitNext(Object, Sinks.EmitFailureHandler)
.static EmissionStrategy
Create anEmissionStrategy
that will indefinitely park emissions on overflow or non-serialized scenarios until it resolves, the emitter is cancelled or the sink is terminated.static discord4j.common.sinks.TimeoutEmissionStrategy
timeoutDrop
(Duration duration) Create anEmissionStrategy
that will retry overflowing and non-serialized emissions until a givenduration
and drop values upon timeout.static discord4j.common.sinks.TimeoutEmissionStrategy
timeoutError
(Duration duration) Create anEmissionStrategy
that will retry overflowing and non-serialized emissions until a givenduration
and error values upon timeout.
-
Method Details
-
timeoutDrop
Create anEmissionStrategy
that will retry overflowing and non-serialized emissions until a givenduration
and drop values upon timeout.- Parameters:
duration
- theDuration
to wait until elements are dropped- Returns:
- a strategy with a drop on timeout behavior
-
timeoutError
Create anEmissionStrategy
that will retry overflowing and non-serialized emissions until a givenduration
and error values upon timeout.- Parameters:
duration
- theDuration
to wait until elements are dropped- Returns:
- a strategy with an error on timeout behavior
-
park
Create anEmissionStrategy
that will indefinitely park emissions on overflow or non-serialized scenarios until it resolves, the emitter is cancelled or the sink is terminated.- Parameters:
duration
- theDuration
indicating how long to disable the emitting thread after each failed attempt- Returns:
- a strategy that awaits emissions on overflowing sinks
-
emitNext
Try emitting a givenelement
to the specifiedsink
, respecting the semantics ofSinks.Many.tryEmitNext(Object)
and the failure handling ofSinks.Many.emitNext(Object, Sinks.EmitFailureHandler)
. Returns whether the emission was successful. Implementations can throw unchecked exceptions likeSinks.EmissionException
or perform side-effects like waiting to determine a result.- Type Parameters:
T
- the type associated with the sink and element- Parameters:
sink
- the target sink where this emission is attemptedelement
- the element pushed to the sink- Returns:
- the result of the emission,
true
if the element was pushed to the sink,false
otherwise
-
emitComplete
Try to terminate the givensink
successfully, respecting the semantics ofSinks.Many.tryEmitComplete()
and the failure handling ofSinks.Many.emitComplete(Sinks.EmitFailureHandler)
. Returns whether the emission was successful. Implementations can throw unchecked exceptions likeSinks.EmissionException
or perform side-effects like waiting to determine a result.- Type Parameters:
T
- the type associated with the sink and element- Parameters:
sink
- the target sink where this emission is attempted- Returns:
- the result of the emission,
true
if the sink was terminated successfully,false
otherwise
-
emitError
Try to fail the givensink
, respecting the semantics ofSinks.Many.tryEmitError(Throwable)
and the failure handling ofSinks.Many.emitError(Throwable, Sinks.EmitFailureHandler)
. Returns whether the emission was successful. Implementations can throw unchecked exceptions likeSinks.EmissionException
or perform side-effects like waiting to determine a result.- Type Parameters:
T
- the type associated with the sink and element- Parameters:
sink
- the target sink where this emission is attemptederror
- the exception to signal, non-null- Returns:
- the result of the emission,
true
if the failure was correctly emitted,false
otherwise
-