join
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.
Note that the job becomes complete only when all its children are complete.
This suspending function is cancellable and always checks for a cancellation of the 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 throws CancellationException if the child had failed, since a failure of a child coroutine cancels parent by default, unless the child was launched from within supervisorScope.
This function can be used in select invocation with onJoin clause. Use isCompleted to check for a completion of this job without waiting.
There is cancelAndJoin function that combines an invocation of cancel and join
.