public CancellableContinuation<T> extends Job
Cancellable continuation. Its job is completed when it is resumed or cancelled. When cancel function is explicitly invoked, this continuation immediately resumes with CancellationException or with the specified cancel cause.
Cancellable continuation has three states (as subset of interface Job states):
| State | isActive | isCompleted | isCancelled |
| ----------------------------------- | ---------- | ------------- | ------------- |
| Active (initial state) | true | false | false |
| Resumed (final completed state) | false | true | false |
| Canceled (final completed state)| false | true | true |
Invocation of cancel transitions this continuation from active to cancelled state, while invocation of resume or resumeWithException transitions it from active to resumed state.
A cancelled continuation implies that it is completed.
Invocation of resume or resumeWithException in resumed state produces IllegalStateException but is ignored in cancelled state.
+-----------+ resume +---------+
| Active | ----------> | Resumed |
+-----------+ +---------+
|
| cancel
V
+-----------+
| Cancelled |
+-----------+
Job.DefaultImpls, Job.Key| Modifier and Type | Method and Description |
|---|---|
void |
initCancellability()
Makes this continuation cancellable. Use it with
holdCancellability optional parameter to
suspendCancellableCoroutine function. It throws IllegalStateException if invoked more than once. |
boolean |
isCancelled()
Returns
true if this continuation was cancelled. |
void |
resumeUndispatched(CoroutineDispatcher $receiver,
T value)
Resumes this continuation with a given value in the invoker thread without going though
dispatch function of the
class CoroutineDispatcher in the context.
This function is designed to be used only by the class CoroutineDispatcher implementations themselves.
It should not be used in general code. |
void |
resumeUndispatchedWithException(CoroutineDispatcher $receiver,
java.lang.Throwable exception)
Resumes this continuation with a given exception in the invoker thread without going though
dispatch function of the
class CoroutineDispatcher in the context.
This function is designed to be used only by the class CoroutineDispatcher implementations themselves.
It should not be used in general code. |
attachChild, cancel, cancelChildren, getCancellationException, getOnJoin, invokeOnCompletion, isActive, isCancelled, isCompleted, join, startboolean isCancelled()
Returns true if this continuation was cancelled.
It implies that isActive is false and isCompleted is true.
void initCancellability()
Makes this continuation cancellable. Use it with holdCancellability optional parameter to
suspendCancellableCoroutine function. It throws IllegalStateException if invoked more than once.
void resumeUndispatched(CoroutineDispatcher $receiver, T value)
Resumes this continuation with a given value in the invoker thread without going though
dispatch function of the class CoroutineDispatcher in the context.
This function is designed to be used only by the class CoroutineDispatcher implementations themselves.
It should not be used in general code.
void resumeUndispatchedWithException(CoroutineDispatcher $receiver, java.lang.Throwable exception)
Resumes this continuation with a given exception in the invoker thread without going though
dispatch function of the class CoroutineDispatcher in the context.
This function is designed to be used only by the class CoroutineDispatcher implementations themselves.
It should not be used in general code.