public interface Disposable
Modifier and Type | Method and Description |
---|---|
void |
dispose()
Dispose the resource, the operation should be idempotent.
|
static @NonNull Disposable |
disposed()
Returns a shared, disposed
Disposable instance. |
static @NonNull Disposable |
empty()
Returns a new, non-disposed
Disposable instance. |
static @NonNull Disposable |
fromAction(@NonNull Action action)
Construct a
Disposable by wrapping a Action that is
executed exactly once when the Disposable is disposed. |
static @NonNull Disposable |
fromAutoCloseable(@NonNull AutoCloseable autoCloseable)
Construct a
Disposable by wrapping an AutoCloseable that is
closed exactly once when the Disposable is disposed. |
static @NonNull Disposable |
fromFuture(@NonNull Future<?> future)
Construct a
Disposable by wrapping a Future that is
cancelled exactly once when the Disposable is disposed. |
static @NonNull Disposable |
fromFuture(@NonNull Future<?> future,
boolean allowInterrupt)
Construct a
Disposable by wrapping a Future that is
cancelled exactly once when the Disposable is disposed. |
static @NonNull Disposable |
fromRunnable(@NonNull Runnable run)
Construct a
Disposable by wrapping a Runnable that is
executed exactly once when the Disposable is disposed. |
static @NonNull Disposable |
fromSubscription(@NonNull Subscription subscription)
Construct a
Disposable by wrapping a Subscription that is
cancelled exactly once when the Disposable is disposed. |
boolean |
isDisposed()
Returns true if this resource has been disposed.
|
static @NonNull AutoCloseable |
toAutoCloseable(@NonNull Disposable disposable)
Construct an
AutoCloseable by wrapping a Disposable that is
disposed when the returned AutoCloseable is closed. |
void dispose()
boolean isDisposed()
@NonNull static @NonNull Disposable fromRunnable(@NonNull Runnable run)
Disposable
by wrapping a Runnable
that is
executed exactly once when the Disposable
is disposed.run
- the Runnable
to wrapDisposable
instanceNullPointerException
- if run
is null
@NonNull static @NonNull Disposable fromAction(@NonNull Action action)
Disposable
by wrapping a Action
that is
executed exactly once when the Disposable
is disposed.action
- the Action
to wrapDisposable
instanceNullPointerException
- if action
is null
@NonNull static @NonNull Disposable fromFuture(@NonNull Future<?> future)
Disposable
by wrapping a Future
that is
cancelled exactly once when the Disposable
is disposed.
The Future
is cancelled with mayInterruptIfRunning == true
.
future
- the Future
to wrapDisposable
instanceNullPointerException
- if future
is null
fromFuture(Future, boolean)
@NonNull static @NonNull Disposable fromFuture(@NonNull Future<?> future, boolean allowInterrupt)
Disposable
by wrapping a Future
that is
cancelled exactly once when the Disposable
is disposed.future
- the Future
to wrapallowInterrupt
- if true, the future cancel happens via Future.cancel(true)
Disposable
instanceNullPointerException
- if future
is null
@NonNull static @NonNull Disposable fromSubscription(@NonNull Subscription subscription)
Disposable
by wrapping a Subscription
that is
cancelled exactly once when the Disposable
is disposed.subscription
- the Runnable
to wrapDisposable
instanceNullPointerException
- if subscription
is null
@NonNull static @NonNull Disposable fromAutoCloseable(@NonNull AutoCloseable autoCloseable)
Disposable
by wrapping an AutoCloseable
that is
closed exactly once when the Disposable
is disposed.autoCloseable
- the AutoCloseable
to wrapDisposable
instanceNullPointerException
- if autoCloseable
is null
@NonNull static @NonNull AutoCloseable toAutoCloseable(@NonNull Disposable disposable)
AutoCloseable
by wrapping a Disposable
that is
disposed when the returned AutoCloseable
is closed.disposable
- the Disposable
instanceAutoCloseable
instanceNullPointerException
- if disposable
is null
@NonNull static @NonNull Disposable empty()
Disposable
instance.Disposable
instance@NonNull static @NonNull Disposable disposed()
Disposable
instance.Disposable
instance