Interface FlowableEmitter<T>
-
- Type Parameters:
T- the value type to emit
- All Superinterfaces:
Emitter<T>
- All Known Implementing Classes:
FlowableCreate.BaseEmitter,FlowableCreate.BufferAsyncEmitter,FlowableCreate.DropAsyncEmitter,FlowableCreate.ErrorAsyncEmitter,FlowableCreate.LatestAsyncEmitter,FlowableCreate.MissingEmitter,FlowableCreate.NoOverflowBaseAsyncEmitter,FlowableCreate.SerializedEmitter
public interface FlowableEmitter<@NonNull T> extends Emitter<T>
Abstraction over a Reactive StreamsSubscriberthat allows associating a resource with it and exposes the current number of downstream requested amount.The
Emitter.onNext(Object),Emitter.onError(Throwable),tryOnError(Throwable)andEmitter.onComplete()methods should be called in a sequential manner, just like theSubscriber's methods. Use theFlowableEmittertheserialize()method returns instead of the originalFlowableEmitterinstance provided by the generator routine if you want to ensure this. The other methods are thread-safe.The emitter allows the registration of a single resource, in the form of a
DisposableorCancellableviasetDisposable(Disposable)orsetCancellable(Cancellable)respectively. The emitter implementations will dispose/cancel this instance when the downstream cancels the flow or after the event generator logic callsEmitter.onError(Throwable),Emitter.onComplete()or whentryOnError(Throwable)succeeds.Only one
DisposableorCancellableobject can be associated with the emitter at a time. Calling eithersetmethod will dispose/cancel any previous object. If there is a need for handling multiple resources, one can create aCompositeDisposableand associate that with the emitter instead.The
Cancellableis logically equivalent toDisposablebut allows using cleanup logic that can throw a checked exception (such as manyclose()methods on Java IO components). Since the release of resources happens after the terminal events have been delivered or the sequence gets cancelled, exceptions throw withinCancellableare routed to the global error handler viaRxJavaPlugins.onError(Throwable).
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanisCancelled()Returns true if the downstream cancelled the sequence or the emitter was terminated viaEmitter.onError(Throwable),Emitter.onComplete()or a successfultryOnError(Throwable).longrequested()The current outstanding request amount.@NonNull FlowableEmitter<T>serialize()Ensures that calls toonNext,onErrorandonCompleteare properly serialized.voidsetCancellable(@Nullable Cancellable c)Sets aCancellableon this emitter; any previousDisposableorCancellablewill be disposed/cancelled.voidsetDisposable(@Nullable Disposable d)Sets a Disposable on this emitter; any previousDisposableorCancellablewill be disposed/cancelled.booleantryOnError(@NonNull java.lang.Throwable t)Attempts to emit the specifiedThrowableerror if the downstream hasn't cancelled the sequence or is otherwise terminated, returning false if the emission is not allowed to happen due to lifecycle restrictions.-
Methods inherited from interface io.reactivex.rxjava3.core.Emitter
onComplete, onError, onNext
-
-
-
-
Method Detail
-
setDisposable
void setDisposable(@Nullable @Nullable Disposable d)
Sets a Disposable on this emitter; any previousDisposableorCancellablewill be disposed/cancelled.This method is thread-safe.
- Parameters:
d- the disposable,nullis allowed
-
setCancellable
void setCancellable(@Nullable @Nullable Cancellable c)
Sets aCancellableon this emitter; any previousDisposableorCancellablewill be disposed/cancelled.This method is thread-safe.
- Parameters:
c- theCancellableresource,nullis allowed
-
requested
long requested()
The current outstanding request amount.This method is thread-safe.
- Returns:
- the current outstanding request amount
-
isCancelled
boolean isCancelled()
Returns true if the downstream cancelled the sequence or the emitter was terminated viaEmitter.onError(Throwable),Emitter.onComplete()or a successfultryOnError(Throwable).This method is thread-safe.
- Returns:
- true if the downstream cancelled the sequence or the emitter was terminated
-
serialize
@NonNull @NonNull FlowableEmitter<T> serialize()
Ensures that calls toonNext,onErrorandonCompleteare properly serialized.- Returns:
- the serialized
FlowableEmitter
-
tryOnError
boolean tryOnError(@NonNull @NonNull java.lang.Throwable t)
Attempts to emit the specifiedThrowableerror if the downstream hasn't cancelled the sequence or is otherwise terminated, returning false if the emission is not allowed to happen due to lifecycle restrictions.Unlike
Emitter.onError(Throwable), theRxjavaPlugins.onErroris not called if the error could not be delivered.History: 2.1.1 - experimental
- Parameters:
t- the throwable error to signal if possible- Returns:
- true if successful, false if the downstream is not able to accept further events
- Since:
- 2.2
-
-