public class SupervisorKt
Modifier and Type | Method and Description |
---|---|
static Job |
SupervisorJob(Job parent)
Creates a new supervisor job object in an active state.
Children of a supervisor job can fail independently of each other.
|
static <R> java.lang.Object |
supervisorScope(kotlin.jvm.functions.Function2<? super kotlinx.coroutines.CoroutineScope,? super kotlin.coroutines.experimental.Continuation<? super R>,? extends java.lang.Object> block,
kotlin.coroutines.experimental.Continuation<? super R> p)
Creates new
interface CoroutineScope with SupervisorKt.SupervisorJob and calls the specified suspend block with this scope.
The provided scope inherits its CoroutineScope.getCoroutineContext from the outer scope, but overrides
context's interface Job with SupervisorKt.SupervisorJob . |
public static Job SupervisorJob(Job parent)
Creates a new supervisor job object in an active state. Children of a supervisor job can fail independently of each other.
A failure or cancellation of a child does not cause the supervisor job to fail and does not affect its other children, so a supervisor can implement a custom policy for handling failures of its children:
A failure of a child job that was created using BuildersKt.launch
can be handled via interface CoroutineExceptionHandler
in the context.
A failure of a child job that was created using BuildersKt.async
can be handled via Deferred.await
on the resulting deferred value.
If parent job is specified, then this supervisor job becomes a child job of its parent and is cancelled when its
parent fails or is cancelled. All this supervisor's children are cancelled in this case, too. The invocation of
Job.cancel
with exception (other than CancellationException) on this supervisor job also cancels parent.
parent
- an optional parent job.BuildersKt.launch
,
interface CoroutineExceptionHandler
,
BuildersKt.async
,
Deferred.await
,
Job.cancel
public static <R> java.lang.Object supervisorScope(kotlin.jvm.functions.Function2<? super kotlinx.coroutines.CoroutineScope,? super kotlin.coroutines.experimental.Continuation<? super R>,? extends java.lang.Object> block, kotlin.coroutines.experimental.Continuation<? super R> p)
Creates new interface CoroutineScope
with SupervisorKt.SupervisorJob
and calls the specified suspend block with this scope.
The provided scope inherits its CoroutineScope.getCoroutineContext
from the outer scope, but overrides
context's interface Job
with SupervisorKt.SupervisorJob
.
A failure of a child does not cause this scope to fail and does not affect its other children,
so a custom policy for handling failures of its children can be implemented. See SupervisorKt.SupervisorJob
for details.
A failure of the scope itself (exception thrown in the block or cancellation) fails the scope with all its children,
but does not cancel parent job.