Class SequentialDisposable

java.lang.Object
java.util.concurrent.atomic.AtomicReference<Disposable>
io.reactivex.rxjava3.internal.disposables.SequentialDisposable
All Implemented Interfaces:
Disposable, Serializable

public final class SequentialDisposable extends AtomicReference<Disposable> implements Disposable
A Disposable container that allows updating/replacing a Disposable atomically and with respect of disposing the container itself.

The class extends AtomicReference directly so watch out for the API leak!

Since:
2.0
See Also:
  • Field Details

  • Constructor Details

    • SequentialDisposable

      public SequentialDisposable()
      Constructs an empty SequentialDisposable.
    • SequentialDisposable

      public SequentialDisposable(Disposable initial)
      Construct a SequentialDisposable with the initial Disposable provided.
      Parameters:
      initial - the initial disposable, null allowed
  • Method Details

    • update

      public boolean update(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

      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:
    • dispose

      public void dispose()
      Description copied from interface: Disposable
      Dispose the resource, the operation should be idempotent.
      Specified by:
      dispose in interface Disposable
    • isDisposed

      public boolean isDisposed()
      Description copied from interface: Disposable
      Returns true if this resource has been disposed.
      Specified by:
      isDisposed in interface Disposable
      Returns:
      true if this resource has been disposed