Top Description Fields Constructors Methods
io.reactivex.rxjava3.disposables

public final Class SerialDisposable

extends Object
implements Disposable
Class Inheritance
All Implemented Interfaces
io.reactivex.rxjava3.disposables.Disposable
Imports
java.util.concurrent.atomic.AtomicReference, io.reactivex.rxjava3.annotations.Nullable, io.reactivex.rxjava3.internal.disposables.DisposableHelper

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

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

Constructor Summary

AccessConstructor and Description
public
SerialDisposable()

Constructs an empty SerialDisposable.

public
SerialDisposable(@Nullable Disposable
the initial Disposable instance to use, null allowed
initialDisposable
)

Constructs a SerialDisposable with the given initial Disposable instance.

Method Summary

Modifier and TypeMethod and Description
public void
dispose()

Implements io.reactivex.rxjava3.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.
public @Nullable Disposable

Returns:

the current Disposable, may be null
get
()

Returns the currently contained Disposable or null if this container is empty.

public boolean
isDisposed()

Implements io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.
public boolean

Returns:

true if the operation succeeded, false if the container has been disposed
replace
(@Nullable Disposable
the Disposable to set, may be null
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.

public boolean

Returns:

true if the operation succeeded, false if the container has been disposed
set
(@Nullable Disposable
the Disposable to set, may be null
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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

resourceback to summary
pack-priv final AtomicReference<Disposable> resource

Constructor Detail

SerialDisposableback to summary
public SerialDisposable()

Constructs an empty SerialDisposable.

SerialDisposableback to summary
public SerialDisposable(@Nullable Disposable initialDisposable)

Constructs a SerialDisposable with the given initial Disposable instance.

Parameters
initialDisposable:@Nullable Disposable

the initial Disposable instance to use, null allowed

Method Detail

disposeback to summary
public void dispose()

Implements io.reactivex.rxjava3.disposables.Disposable.dispose.

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

Dispose the resource, the operation should be idempotent.

Annotations
@Override
getback to summary
public @Nullable Disposable get()

Returns the currently contained Disposable or null if this container is empty.

Returns:@Nullable Disposable

the current Disposable, may be null

Annotations
@Nullable
isDisposedback to summary
public boolean isDisposed()

Implements io.reactivex.rxjava3.disposables.Disposable.isDisposed.

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

Returns true if this resource has been disposed.

Returns:boolean

true if this resource has been disposed

Annotations
@Override
replaceback to summary
public 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.

Parameters
next:@Nullable Disposable

the Disposable to set, may be null

Returns:boolean

true if the operation succeeded, false if the container has been disposed

See Also
set(Disposable)
setback to summary
public 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.

Parameters
next:@Nullable Disposable

the Disposable to set, may be null

Returns:boolean

true if the operation succeeded, false if the container has been disposed

See Also
replace(Disposable)