public class JobKt
| Modifier and Type | Method and Description |
|---|---|
static Job |
Job(Job parent)
Creates a new job object in an active state.
A failure of any child of this job immediately causes this job to fail, too, and cancels the rest of its children.
|
static boolean |
cancel(kotlin.coroutines.experimental.CoroutineContext $receiver)
Cancels
interface Job of this context. The result is true if the job was
cancelled as a result of this invocation or was already being cancelled and
false if there is no job in the context or if it was already completed. See Job.cancel for details. |
static boolean |
cancel(kotlin.coroutines.experimental.CoroutineContext $receiver,
java.lang.Throwable cause)
Cancels
interface Job of this context with an optional cancellation cause. The result is true if the job was
cancelled as a result of this invocation and false if there is no job in the context or if it was already
cancelled or completed. See Job.cancel for details. |
static java.lang.Object |
cancelAndJoin(Job $receiver,
kotlin.coroutines.experimental.Continuation<? super kotlin.Unit> p)
Cancels the job and suspends invoking coroutine until the cancelled job is complete.
|
static void |
cancelChildren(kotlin.coroutines.experimental.CoroutineContext $receiver)
Cancels all children of the
interface Job in this context, without touching the the state of this job itself.
It does not do anything if there is no job in the context or it has no children. |
static void |
cancelChildren(kotlin.coroutines.experimental.CoroutineContext $receiver,
java.lang.Throwable cause)
Cancels all children of the
interface Job in this context with an optional cancellation cause,
without touching the the state of this job itself.
It does not do anything if there is no job in the context or it has no children. |
static void |
cancelChildren(Job $receiver,
java.lang.Throwable cause)
Cancels all
Job.getChildren jobs of this coroutine with the given cause using Job.cancel
for all of them. Unlike Job.cancel on this job as a whole, the state of this job itself is not affected. |
static void |
cancelFutureOnCancellation(CancellableContinuation<?> $receiver,
java.util.concurrent.Future<?> future)
Cancels a specified future when this job is cancelled.
This is a shortcut for the following code with slightly more efficient implementation (one fewer object created).
|
static DisposableHandle |
cancelFutureOnCompletion(CancellableContinuation<?> $receiver,
java.util.concurrent.Future<?> future)
Deprecated.
|
static boolean |
isActive(kotlin.coroutines.experimental.CoroutineContext $receiver)
Returns
true when the interface Job of the coroutine in this context is still active
(has not completed and was not cancelled yet). |
public static boolean isActive(kotlin.coroutines.experimental.CoroutineContext $receiver)
Returns true when the interface Job of the coroutine in this context is still active
(has not completed and was not cancelled yet).
Check this property in long-running computation loops to support cancellation when CoroutineScope.isActive is not available:
while (coroutineContext.isActive) {
// do some computation
}
The coroutineContext.isActive expression is a shortcut for coroutineContext[Job]?.isActive == true.
See Job.isActive.
interface Job,
Job.isActivepublic static Job Job(Job parent)
Creates a new job object in an active state. A failure of any child of this job immediately causes this job to fail, too, and cancels the rest of its children.
To handle children failure independently of each other use SupervisorKt.SupervisorJob.
If parent job is specified, then this job becomes a child job of its parent and
is cancelled when its parent fails or is cancelled. All this job's children are cancelled in this case, too.
The invocation of Job.cancel with exception (other than CancellationException) on this job also cancels parent.
parent - an optional parent job.SupervisorKt.SupervisorJob,
Job.cancelpublic static boolean cancel(kotlin.coroutines.experimental.CoroutineContext $receiver)
Cancels interface Job of this context. The result is true if the job was
cancelled as a result of this invocation or was already being cancelled and
false if there is no job in the context or if it was already completed. See Job.cancel for details.
interface Job,
Job.cancelpublic static boolean cancel(kotlin.coroutines.experimental.CoroutineContext $receiver,
java.lang.Throwable cause)
Cancels interface Job of this context with an optional cancellation cause. The result is true if the job was
cancelled as a result of this invocation and false if there is no job in the context or if it was already
cancelled or completed. See Job.cancel for details.
Note: This is an experimental api. Cancellation of a job with exception may change its semantics in the future.
interface Job,
Job.cancelpublic static java.lang.Object cancelAndJoin(Job $receiver, kotlin.coroutines.experimental.Continuation<? super kotlin.Unit> p)
Cancels the job and suspends invoking coroutine until the cancelled job is complete.
This suspending function is cancellable and always checks for the cancellation of invoking coroutine's Job.
If the interface Job of the invoking coroutine is cancelled or completed when this
suspending function is invoked or while it is suspended, this function
throws CancellationException.
In particular, it means that a parent coroutine invoking cancelAndJoin on a child coroutine that was started using
launch(coroutineContext) { ... } builder throws CancellationException if the child
had crashed, unless a non-standard interface CoroutineExceptionHandler is installed in the context.
This is a shortcut for the invocation of Job.cancel followed by Job.join.
public static void cancelChildren(kotlin.coroutines.experimental.CoroutineContext $receiver)
Cancels all children of the interface Job in this context, without touching the the state of this job itself.
It does not do anything if there is no job in the context or it has no children.
interface Jobpublic static void cancelChildren(kotlin.coroutines.experimental.CoroutineContext $receiver,
java.lang.Throwable cause)
Cancels all children of the interface Job in this context with an optional cancellation cause,
without touching the the state of this job itself.
It does not do anything if there is no job in the context or it has no children.
Note: This is an experimental api. Cancellation of a job with exception may change its semantics in the future.
interface Jobpublic static void cancelChildren(Job $receiver, java.lang.Throwable cause)
Cancels all Job.getChildren jobs of this coroutine with the given cause using Job.cancel
for all of them. Unlike Job.cancel on this job as a whole, the state of this job itself is not affected.
Job.getChildren,
Job.cancel,
Job.cancelpublic static void cancelFutureOnCancellation(CancellableContinuation<?> $receiver, java.util.concurrent.Future<?> future)
Cancels a specified future when this job is cancelled. This is a shortcut for the following code with slightly more efficient implementation (one fewer object created).
invokeOnCancellation { future.cancel(false) }
public static DisposableHandle cancelFutureOnCompletion(CancellableContinuation<?> $receiver, java.util.concurrent.Future<?> future)
Cancels a specified future when this job is cancelled. This is a shortcut for the following code with slightly more efficient implementation (one fewer object created).
invokeOnCompletion { future.cancel(false) }