Top Description Methods
io.reactivex.rxjava3.core

public Interface CompletableEmitter

Known Direct Implementers
io.reactivex.rxjava3.internal.operators.completable.CompletableCreate.Emitter
Imports
io.reactivex.rxjava3.annotations.*, io.reactivex.rxjava3.disposables.Disposable, io.reactivex.rxjava3.functions.Cancellable

Abstraction over an RxJava CompletableObserver that allows associating a resource with it.

All methods are safe to call from multiple threads, but note that there is no guarantee whose terminal event will win and get delivered to the downstream.

Calling onComplete() multiple times has no effect. Calling onError(Throwable) multiple times or after onComplete will route the exception into the global error handler via io.reactivex.rxjava3.plugins.RxJavaPlugins#onError(Throwable).

The emitter allows the registration of a single resource, in the form of a Disposable or Cancellable via setDisposable(Disposable) or setCancellable(Cancellable) respectively. The emitter implementations will dispose/cancel this instance when the downstream cancels the flow or after the event generator logic calls onError(Throwable), onComplete() or when tryOnError(Throwable) succeeds.

Only one Disposable or Cancellable object can be associated with the emitter at a time. Calling either set method will dispose/cancel any previous object. If there is a need for handling multiple resources, one can create a io.reactivex.rxjava3.disposables.CompositeDisposable and associate that with the emitter instead.

The Cancellable is logically equivalent to Disposable but allows using cleanup logic that can throw a checked exception (such as many close() 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 within Cancellable are routed to the global error handler via io.reactivex.rxjava3.plugins.RxJavaPlugins#onError(Throwable).

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the downstream disposed the sequence or the emitter was terminated
isDisposed
()

Returns true if the downstream disposed the sequence or the emitter was terminated via onError(Throwable), onComplete or a successful tryOnError(Throwable).

public void
onComplete()

Signal the completion.

public void
onError(@NonNull Throwable
the exception, not null
t
)

Signal an exception.

public void
setCancellable(@Nullable Cancellable
the cancellable resource, null is allowed
c
)

Sets a Cancellable on this emitter; any previous Disposable or Cancellable will be disposed/cancelled.

public void
setDisposable(@Nullable Disposable
the disposable, null is allowed
d
)

Sets a Disposable on this emitter; any previous Disposable or Cancellable will be disposed/cancelled.

public boolean

Returns:

true if successful, false if the downstream is not able to accept further events
tryOnError
(@NonNull Throwable
the throwable error to signal if possible
t
)

Attempts to emit the specified Throwable error 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.

Method Detail

isDisposedback to summary
public boolean isDisposed()

Returns true if the downstream disposed the sequence or the emitter was terminated via onError(Throwable), onComplete or a successful tryOnError(Throwable).

This method is thread-safe.

Returns:boolean

true if the downstream disposed the sequence or the emitter was terminated

onCompleteback to summary
public void onComplete()

Signal the completion.

onErrorback to summary
public void onError(@NonNull Throwable t)

Signal an exception.

Parameters
t:@NonNull Throwable

the exception, not null

setCancellableback to summary
public void setCancellable(@Nullable Cancellable c)

Sets a Cancellable on this emitter; any previous Disposable or Cancellable will be disposed/cancelled.

Parameters
c:@Nullable Cancellable

the cancellable resource, null is allowed

setDisposableback to summary
public void setDisposable(@Nullable Disposable d)

Sets a Disposable on this emitter; any previous Disposable or Cancellable will be disposed/cancelled.

Parameters
d:@Nullable Disposable

the disposable, null is allowed

tryOnErrorback to summary
public boolean tryOnError(@NonNull Throwable t)

Attempts to emit the specified Throwable error 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 onError(Throwable), the RxjavaPlugins.onError is not called if the error could not be delivered.

History: 2.1.1 - experimental

Parameters
t:@NonNull Throwable

the throwable error to signal if possible

Returns:boolean

true if successful, false if the downstream is not able to accept further events

Since
2.2