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

public final Enum DisposableHelper

extends Enum<DisposableHelper>
implements Disposable
Class Inheritance
All Implemented Interfaces
io.reactivex.rxjava3.disposables.Disposable
Imports
java.util.Objects, java.util.concurrent.atomic.AtomicReference, io.reactivex.rxjava3.disposables.Disposable, io.reactivex.rxjava3.exceptions.ProtocolViolationException, io.reactivex.rxjava3.plugins.RxJavaPlugins

Utility methods for working with Disposables atomically.

Field Summary

Modifier and TypeField and Description
public static final DisposableHelper
DISPOSED

The singleton instance representing a terminal, disposed state, don't leak it.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

true if the current thread managed to dispose the Disposable
dispose
(AtomicReference<Disposable>
the target field
field
)

Atomically disposes the Disposable in the field if not already disposed.

public void
dispose()

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

Dispose the resource, the operation should be idempotent.
public static boolean

Returns:

true if d is DISPOSED
isDisposed
(Disposable
the disposable to check
d
)

Checks if the given Disposable is the common DISPOSED enum value.

public boolean
isDisposed()

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

Returns true if this resource has been disposed.
public static boolean

Returns:

true if the operation succeeded, false if the target field contained the common DISPOSED instance and the given disposable (if not null) is disposed.
replace
(AtomicReference<Disposable>
the target field to change
field
,
Disposable
the new disposable, null allowed
d
)

Atomically replaces the Disposable in the field with the given new Disposable but does not dispose the old one.

public static void
reportDisposableSet()

Reports that the disposable is already set to the RxJavaPlugins error handler.

public static boolean

Returns:

true if successful, false if the field contains the DISPOSED instance.
set
(AtomicReference<Disposable>
the target field
field
,
Disposable
the new Disposable to set
d
)

Atomically sets the field and disposes the old contents.

public static boolean

Returns:

true if the operation succeeded, false
setOnce
(AtomicReference<Disposable>
the target field
field
,
Disposable
the disposable to set, not null
d
)

Atomically sets the field to the given non-null Disposable and returns true or returns false if the field is non-null.

public static boolean

Returns:

true if successful, false otherwise
trySet
(AtomicReference<Disposable>
the target field
field
,
Disposable
the disposable to set
d
)

Atomically tries to set the given Disposable on the field if it is null or disposes it if the field contains DISPOSED.

public static boolean

Returns:

true if the validation succeeded
validate
(Disposable
the current Disposable, expected to be null
current
,
Disposable
the next Disposable, expected to be non-null
next
)

Verifies that current is null, next is not null, otherwise signals errors to the RxJavaPlugins and returns false.

public static DisposableHelper
public static DisposableHelper[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

DISPOSEDback to summary
public static final DisposableHelper DISPOSED

The singleton instance representing a terminal, disposed state, don't leak it.

Constructor Detail

DisposableHelperback to summary
private DisposableHelper()

Method Detail

disposeback to summary
public static boolean dispose(AtomicReference<Disposable> field)

Atomically disposes the Disposable in the field if not already disposed.

Parameters
field:AtomicReference<Disposable>

the target field

Returns:boolean

true if the current thread managed to dispose the Disposable

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
isDisposedback to summary
public static boolean isDisposed(Disposable d)

Checks if the given Disposable is the common DISPOSED enum value.

Parameters
d:Disposable

the disposable to check

Returns:boolean

true if d is DISPOSED

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 static boolean replace(AtomicReference<Disposable> field, Disposable d)

Atomically replaces the Disposable in the field with the given new Disposable but does not dispose the old one.

Parameters
field:AtomicReference<Disposable>

the target field to change

d:Disposable

the new disposable, null allowed

Returns:boolean

true if the operation succeeded, false if the target field contained the common DISPOSED instance and the given disposable (if not null) is disposed.

reportDisposableSetback to summary
public static void reportDisposableSet()

Reports that the disposable is already set to the RxJavaPlugins error handler.

setback to summary
public static boolean set(AtomicReference<Disposable> field, Disposable d)

Atomically sets the field and disposes the old contents.

Parameters
field:AtomicReference<Disposable>

the target field

d:Disposable

the new Disposable to set

Returns:boolean

true if successful, false if the field contains the DISPOSED instance.

setOnceback to summary
public static boolean setOnce(AtomicReference<Disposable> field, Disposable d)

Atomically sets the field to the given non-null Disposable and returns true or returns false if the field is non-null. If the target field contains the common DISPOSED instance, the supplied disposable is disposed. If the field contains other non-null Disposable, an IllegalStateException is signalled to the RxJavaPlugins.onError hook.

Parameters
field:AtomicReference<Disposable>

the target field

d:Disposable

the disposable to set, not null

Returns:boolean

true if the operation succeeded, false

trySetback to summary
public static boolean trySet(AtomicReference<Disposable> field, Disposable d)

Atomically tries to set the given Disposable on the field if it is null or disposes it if the field contains DISPOSED.

Parameters
field:AtomicReference<Disposable>

the target field

d:Disposable

the disposable to set

Returns:boolean

true if successful, false otherwise

validateback to summary
public static boolean validate(Disposable current, Disposable next)

Verifies that current is null, next is not null, otherwise signals errors to the RxJavaPlugins and returns false.

Parameters
current:Disposable

the current Disposable, expected to be null

next:Disposable

the next Disposable, expected to be non-null

Returns:boolean

true if the validation succeeded

valueOfback to summary
public static DisposableHelper valueOf(String name)
valuesback to summary
public static DisposableHelper[] values()