public final class

SerialDisposable

extends Object
implements Disposable
java.lang.Object
   ↳ io.reactivex.disposables.SerialDisposable

Class Overview

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.

Summary

Public Constructors
SerialDisposable()
Constructs an empty SerialDisposable.
SerialDisposable(Disposable initialDisposable)
Constructs a SerialDisposable with the given initial Disposable instance.
Public Methods
void dispose()
Dispose the resource, the operation should be idempotent.
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(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(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.
[Expand]
Inherited Methods
From class java.lang.Object
From interface io.reactivex.disposables.Disposable

Public Constructors

public SerialDisposable ()

Constructs an empty SerialDisposable.

public SerialDisposable (Disposable initialDisposable)

Constructs a SerialDisposable with the given initial Disposable instance.

Parameters
initialDisposable the initial Disposable instance to use, null allowed

Public Methods

public void dispose ()

Dispose the resource, the operation should be idempotent.

public Disposable get ()

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

Returns
  • the current Disposable, may be null

public boolean isDisposed ()

Returns true if this resource has been disposed.

Returns
  • true if this resource has been disposed

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 the Disposable to set, may be null
Returns
  • true if the operation succeeded, false if the container has been disposed
See Also

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