Class SerialDisposable
java.lang.Object
io.reactivex.rxjava4.disposables.SerialDisposable
- All Implemented Interfaces:
Disposable, AutoCloseable
A Disposable container that allows atomically updating/replacing the contained
Disposable with another Disposable, disposing the old one when updating plus
handling the disposition when the container itself is disposed.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty SerialDisposable.SerialDisposable(@Nullable Disposable initialDisposable) Constructs a SerialDisposable with the given initial Disposable instance. -
Method Summary
Modifier and TypeMethodDescriptionvoiddispose()Dispose the resource, the operation should be idempotent.get()Returns the currently contained Disposable or null if this container is empty.booleanReturns true if this resource has been disposed.booleanreplace(@Nullable 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.booleanset(@Nullable 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 Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Disposable
closeModifier and TypeMethodDescriptiondefault voidclose()Dispose the resource, the operation should be idempotent.
-
Constructor Details
-
SerialDisposable
public SerialDisposable()Constructs an empty SerialDisposable. -
SerialDisposable
Constructs a SerialDisposable with the given initial Disposable instance.- Parameters:
initialDisposable- the initial Disposable instance to use, null allowed
-
-
Method Details
-
set
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:
-
get
Returns the currently contained Disposable or null if this container is empty.- Returns:
- the current Disposable, may be null
-
dispose
public void dispose()Description copied from interface:DisposableDispose the resource, the operation should be idempotent.- Specified by:
disposein interfaceDisposable
-
isDisposed
public boolean isDisposed()Description copied from interface:DisposableReturns true if this resource has been disposed.- Specified by:
isDisposedin interfaceDisposable- Returns:
- true if this resource has been disposed
-