Class SequentialDisposable
java.lang.Object
java.util.concurrent.atomic.AtomicReference<Disposable>
io.reactivex.rxjava3.internal.disposables.SequentialDisposable
- All Implemented Interfaces:
Disposable
,Serializable
A Disposable container that allows updating/replacing a Disposable
atomically and with respect of disposing the container itself.
The class extends AtomicReference directly so watch out for the API leak!
- Since:
- 2.0
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty SequentialDisposable.SequentialDisposable
(Disposable initial) Construct a SequentialDisposable with the initial Disposable provided. -
Method Summary
Modifier and TypeMethodDescriptionvoid
dispose()
Dispose the resource, the operation should be idempotent.boolean
Returns true if this resource has been disposed.boolean
replace
(Disposable next) Atomically: set the next disposable on this container but don't dispose the previous one (if any) or dispose next if the container has been disposed.boolean
update
(Disposable next) Atomically: set the next disposable on this container and dispose the previous one (if any) or dispose next if the container has been disposed.Methods inherited from class java.util.concurrent.atomic.AtomicReference
accumulateAndGet, compareAndExchange, compareAndExchangeAcquire, compareAndExchangeRelease, compareAndSet, get, getAcquire, getAndAccumulate, getAndSet, getAndUpdate, getOpaque, getPlain, lazySet, set, setOpaque, setPlain, setRelease, toString, updateAndGet, weakCompareAndSet, weakCompareAndSetAcquire, weakCompareAndSetPlain, weakCompareAndSetRelease, weakCompareAndSetVolatile
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
-
Constructor Details
-
SequentialDisposable
public SequentialDisposable()Constructs an empty SequentialDisposable. -
SequentialDisposable
Construct a SequentialDisposable with the initial Disposable provided.- Parameters:
initial
- the initial disposable, null allowed
-
-
Method Details
-
update
Atomically: set the next disposable on this container and dispose the previous one (if any) or dispose next if the container has been disposed.- Parameters:
next
- the Disposable to set, may be null- Returns:
- true if the operation succeeded, false if the container has been disposed
- See Also:
-
replace
Atomically: set the next disposable on this container but don't dispose the previous one (if any) or dispose next if the container has been disposed.- Parameters:
next
- the Disposable to set, may be null- Returns:
- true if the operation succeeded, false if the container has been disposed
- See Also:
-
dispose
public void dispose()Description copied from interface:Disposable
Dispose the resource, the operation should be idempotent.- Specified by:
dispose
in interfaceDisposable
-
isDisposed
public boolean isDisposed()Description copied from interface:Disposable
Returns true if this resource has been disposed.- Specified by:
isDisposed
in interfaceDisposable
- Returns:
- true if this resource has been disposed
-