CompletableJob

interface CompletableJob : Job (source)

A job that can be completed using complete function. It is returned by Job() and SupervisorJob() constructor functions.

Inherited Properties

children

abstract val children: Sequence<Job>

Returns a sequence of this job’s children.

isActive

abstract val isActive: Boolean

Returns true when this job is active – it was already started and has not completed nor was cancelled yet. The job that is waiting for its children to complete is still considered to be active if it was not cancelled nor failed.

isCancelled

abstract val isCancelled: Boolean

Returns true if this job was cancelled for any reason, either by explicit invocation of cancel or because it had failed or its child or parent was cancelled. In the general case, it does not imply that the job has already completed, because it may still be finishing whatever it was doing and waiting for its children to complete.

isCompleted

abstract val isCompleted: Boolean

Returns true when this job has completed for any reason. A job that was cancelled or failed and has finished its execution is also considered complete. Job becomes complete only after all its children complete.

onJoin

abstract val onJoin: SelectClause0

Clause for select expression of join suspending function that selects when the job is complete. This clause never fails, even if the job completes exceptionally.

Functions

complete

abstract fun complete(): Boolean

Completes this job. The result is true if this job was completed as a result of this invocation and false otherwise (if it was already completed).

completeExceptionally

abstract fun completeExceptionally(
    exception: Throwable
): Boolean

Completes this job exceptionally with a given exception. The result is true if this job was completed as a result of this invocation and false otherwise (if it was already completed). exception parameter is used as an additional debug information that is not handled by any exception handlers.

Inherited Functions

cancel

abstract fun cancel(
    cause: CancellationException? = null
): Unit

Cancels this job with an optional cancellation cause. A cause can be used to specify an error message or to provide other details on the cancellation reason for debugging purposes. See Job documentation for full explanation of cancellation machinery.

invokeOnCompletion

abstract fun invokeOnCompletion(
    handler: CompletionHandler
): DisposableHandle

Registers handler that is synchronously invoked once on completion of this job. When the job is already complete, then the handler is immediately invoked with the job’s exception or cancellation cause or null. Otherwise, the handler will be invoked once when this job is complete.

join

abstract suspend fun join(): Unit

Suspends the coroutine until this job is complete. This invocation resumes normally (without exception) when the job is complete for any reason and the Job of the invoking coroutine is still active. This function also starts the corresponding coroutine if the Job was still in new state.

start

abstract fun start(): Boolean

Starts coroutine related to this job (if any) if it was not started yet. The result true if this invocation actually started coroutine or false if it was already started or completed.

Extension Properties

isActive

Returns true when the Job of the coroutine in this context is still active (has not completed and was not cancelled yet).

Extension Functions

cancel

fun CoroutineContext.cancel(
    cause: CancellationException? = null
): Unit

Cancels Job of this context with an optional cancellation cause. See Job.cancel for details.

cancel

fun Job.cancel(
    message: String,
    cause: Throwable? = null
): Unit

Cancels current job, including all its children with a specified diagnostic error message. A cause can be specified to provide additional details on a cancellation reason for debugging purposes.

cancelAndJoin

suspend fun Job.cancelAndJoin(): Unit

Cancels the job and suspends the invoking coroutine until the cancelled job is complete.