Top Description Fields Constructors Methods
io.reactivex.observers

public abstract Class DisposableObserver<T>

extends Object
implements Observer<T>, Disposable
Class Inheritance
All Implemented Interfaces
io.reactivex.disposables.Disposable, io.reactivex.Observer
Known Direct Subclasses
io.reactivex.internal.operators.observable.BlockingObservableLatest.BlockingObservableLatestIterator, io.reactivex.internal.operators.observable.BlockingObservableNext.NextObserver, io.reactivex.internal.operators.observable.ObservableBufferBoundarySupplier.BufferBoundaryObserver, io.reactivex.internal.operators.observable.ObservableBufferExactBoundary.BufferBoundaryObserver, io.reactivex.internal.operators.observable.ObservableWindowBoundary.WindowBoundaryInnerObserver, io.reactivex.internal.operators.observable.ObservableWindowBoundarySelector.OperatorWindowBoundaryOpenObserver, io.reactivex.internal.operators.observable.ObservableWindowBoundarySelector.OperatorWindowBoundaryCloseObserver, io.reactivex.internal.operators.observable.ObservableWindowBoundarySupplier.WindowBoundaryInnerObserver, io.reactivex.internal.operators.observable.ObservableDebounce.DebounceObserver.DebounceInnerObserver
Type Parameters
<T>
the received value type
Imports
java.util.concurrent.atomic.AtomicReference, io.reactivex.Observer, io.reactivex.annotations.NonNull, io.reactivex.disposables.Disposable, io.reactivex.internal.disposables.DisposableHelper, io.reactivex.internal.util.EndConsumerHelper

An abstract Observer that allows asynchronous cancellation by implementing Disposable.

All pre-implemented final methods are thread-safe.

Use the public dispose() method to dispose the sequence from within an onNext implementation.

Like all other consumers, DisposableObserver can be subscribed only once. Any subsequent attempt to subscribe it to a new source will yield an IllegalStateException with message "It is not allowed to subscribe with a(n) <class name> multiple times.".

Implementation of onStart(), onNext(Object), onError(Throwable) and onComplete() are not allowed to throw any unchecked exceptions. If for some reason this can't be avoided, use io.reactivex.Observable#safeSubscribe(io.reactivex.Observer) instead of the standard subscribe() method.

Example


Disposable d =
    Observable.range(1, 5)
    .subscribeWith(new DisposableObserver<Integer>() {
        @Override public void onStart() {
            System.out.println("Start!");
        }
        @Override public void onNext(Integer t) {
            if (t == 3) {
                dispose();
            }
            System.out.println(t);
        }
        @Override public void onError(Throwable t) {
            t.printStackTrace();
        }
        @Override public void onComplete() {
            System.out.println("Done!");
        }
    });
// ...
d.dispose();

Field Summary

Modifier and TypeField and Description
pack-priv final AtomicReference<Disposable>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final void
dispose()

Implements io.reactivex.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.
public final boolean
isDisposed()

Implements io.reactivex.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.
protected void
onStart()

Called once the single upstream Disposable is set via onSubscribe.

public final void
onSubscribe(Disposable
the Disposable instance whose Disposable#dispose() can be called anytime to cancel the connection
d
)

Implements io.reactivex.Observer.onSubscribe.

Provides the Observer with the means of cancelling (disposing) the connection (channel) with the Observable in both synchronous (from within onNext(Object)) and asynchronous manner.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

upstreamback to summary
pack-priv final AtomicReference<Disposable> upstream

Constructor Detail

DisposableObserverback to summary
public DisposableObserver()

Method Detail

disposeback to summary
public final void dispose()

Implements io.reactivex.disposables.Disposable.dispose.

Doc from io.reactivex.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.

Annotations
@Override
isDisposedback to summary
public final boolean isDisposed()

Implements io.reactivex.disposables.Disposable.isDisposed.

Doc from io.reactivex.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.

Returns:boolean

true if this resource has been disposed

Annotations
@Override
onStartback to summary
protected void onStart()

Called once the single upstream Disposable is set via onSubscribe.

onSubscribeback to summary
public final void onSubscribe(Disposable d)

Implements io.reactivex.Observer.onSubscribe.

Doc from io.reactivex.Observer.onSubscribe.

Provides the Observer with the means of cancelling (disposing) the connection (channel) with the Observable in both synchronous (from within onNext(Object)) and asynchronous manner.

Parameters
d:Disposable

the Disposable instance whose Disposable#dispose() can be called anytime to cancel the connection

Annotations
@Override