Package io.reactivex.rxjava3.disposables
Class SerialDisposable
- java.lang.Object
-
- io.reactivex.rxjava3.disposables.SerialDisposable
-
- All Implemented Interfaces:
Disposable
public final class SerialDisposable extends java.lang.Object implements Disposable
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.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.concurrent.atomic.AtomicReference<Disposable>
resource
-
Constructor Summary
Constructors Constructor Description SerialDisposable()
Constructs an empty SerialDisposable.SerialDisposable(@Nullable Disposable initialDisposable)
Constructs a SerialDisposable with the given initial Disposable instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
dispose()
Dispose the resource, the operation should be idempotent.@Nullable Disposable
get()
Returns the currently contained Disposable or null if this container is empty.boolean
isDisposed()
Returns true if this resource has been disposed.boolean
replace(@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.boolean
set(@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.
-
-
-
Field Detail
-
resource
final java.util.concurrent.atomic.AtomicReference<Disposable> resource
-
-
Constructor Detail
-
SerialDisposable
public SerialDisposable()
Constructs an empty SerialDisposable.
-
SerialDisposable
public SerialDisposable(@Nullable @Nullable Disposable initialDisposable)
Constructs a SerialDisposable with the given initial Disposable instance.- Parameters:
initialDisposable
- the initial Disposable instance to use, null allowed
-
-
Method Detail
-
set
public boolean set(@Nullable @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.- 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(Disposable)
-
replace
public boolean replace(@Nullable @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.- Parameters:
next
- the Disposable to set, may be null- Returns:
- true if the operation succeeded, false if the container has been disposed
- See Also:
set(Disposable)
-
get
@Nullable public @Nullable Disposable 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: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
-
-