Top Description Methods
io.reactivex

public Interface ObservableEmitter<T>

extends Emitter<T>
Known Direct Implementers
io.reactivex.internal.operators.observable.ObservableCreate.CreateEmitter, io.reactivex.internal.operators.observable.ObservableCreate.SerializedEmitter
Type Parameters
<T>
the value type to emit
Imports
io.reactivex.annotations.*, io.reactivex.disposables.Disposable, io.reactivex.functions.Cancellable

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

The onNext(Object), onError(Throwable), tryOnError(Throwable) and onComplete() methods should be called in a sequential manner, just like the Observer's methods should be. Use the ObservableEmitter the serialize() method returns instead of the original ObservableEmitter instance 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 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.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.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 ObservableEmitter<T>

Returns:

the serialized ObservableEmitter
serialize
()

Ensures that calls to onNext, onError and onComplete are properly serialized.

public void
setCancellable(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(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
(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.

Inherited from io.reactivex.Emitter:
onCompleteonErroronNext

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

serializeback to summary
public ObservableEmitter<T> serialize()

Ensures that calls to onNext, onError and onComplete are properly serialized.

Returns:ObservableEmitter<T>

the serialized ObservableEmitter

Annotations
@NonNull
setCancellableback to summary
public void setCancellable(Cancellable c)

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

Parameters
c:Cancellable

the cancellable resource, null is allowed

setDisposableback to summary
public void setDisposable(Disposable d)

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

Parameters
d:Disposable

the disposable, null is allowed

tryOnErrorback to summary
public boolean tryOnError(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: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