join

abstract suspend fun join(): Unit (source)

Suspends 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.

Note, that the job becomes complete only when all its children are complete.

This suspending function is cancellable and always checks for the cancellation of invoking coroutine’s Job. If the 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 join on a child coroutine that was started using launch(coroutineContext) { ... } builder throws CancellationException if the child had crashed, unless a non-standard CoroutineExceptionHandler if installed in the context.

This function can be used in select invocation with onJoin clause. Use isCompleted to check for completion of this job without waiting.

There is cancelAndJoin function that combines an invocation of cancel and join.