Top Description Fields Constructors Methods
io.reactivex.disposables

public final Class SerialDisposable

extends Object
implements Disposable
Class Inheritance
All Implemented Interfaces
io.reactivex.disposables.Disposable
Imports
java.util.concurrent.atomic.AtomicReference, io.reactivex.annotations.Nullable, io.reactivex.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(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.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.
public 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.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
(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
(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(Disposable initialDisposable)

Constructs a SerialDisposable with the given initial Disposable instance.

Parameters
initialDisposable:Disposable

the initial Disposable instance to use, null allowed

Method Detail

disposeback to summary
public 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
getback to summary
public Disposable get()

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

Returns:Disposable

the current Disposable, may be null

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

Parameters
next: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(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: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)