AbstractCoroutine
abstract class AbstractCoroutine<in T> :
JobSupport,
Job,
Continuation<T>,
CoroutineScope
(source)Abstract base class for implementation of coroutines in coroutine builders.
This class implements completion Continuation, Job, and CoroutineScope interfaces. It stores the result of continuation in the state of the job. This coroutine waits for children coroutines to finish before completing and is cancelled through an intermediate cancelling state.
The following methods are available for override:
- onStart is invoked when coroutine is create in not active state and is started.
- onCancellation is invoked as soon as coroutine is cancelled (becomes cancelling) or when it completes for any reason.
- onCompleted is invoked when coroutine completes with a value.
- onCompletedExceptionally in invoked when coroutines completes with exception.
Parameters
parentContext
- context of the parent coroutine.
active
- when true
(by default) coroutine is created in active state, when false
in new state.
See Job for details.
Constructors
AbstractCoroutine( Abstract base class for implementation of coroutines in coroutine builders. |
Properties
val coroutineContext: CoroutineContext Returns the context of this coroutine. |
Functions
Cancels this job with an optional cancellation cause. The result is |
|
open fun invokeOnCompletion( Registers handler that is synchronously invoked once on cancellation or completion of this job.
When job is already cancelling or complete, then the handler is immediately invoked
with a job’s cancellation cause or |
|
This function is invoked once when this coroutine is cancelled or is completed,
similarly to invokeOnCompletion with |
|
This function is invoked once when job is completed normally with the specified value. |
|
This function is invoked once when job is completed exceptionally with the specified exception. |
|
open fun onStart(): Unit This function is invoked once when non-active coroutine (constructed with |
|
Completes execution of this coroutine normally with the specified value. |
|
Completes execution of this with coroutine exceptionally with the specified exception. |
|
fun start( fun <R> start( Starts this coroutine with the given code block and start strategy. This function shall be invoked at most once on this coroutine. |
Extension Functions
fun Job.cancelFutureOnCompletion( Cancels a specified future when this job is complete. |
|
fun <T> AbstractCoroutine<T>.startUndispatchedOrReturn( fun <T, R> AbstractCoroutine<T>.startUndispatchedOrReturn( Starts this coroutine with the given code block in the same context and returns result when it completes without suspnesion. This function shall be invoked at most once on this coroutine. |