suspendCancellableCoroutine

inline suspend fun <T> suspendCancellableCoroutine(
    holdCancellability: Boolean = false,
    crossinline block: (CancellableContinuation<T>) -> Unit
): T
(source)

Suspends coroutine similar to suspendCoroutine, but provide an implementation of CancellableContinuation to the block. This function throws CancellationException if the coroutine is cancelled or completed while suspended.

If holdCancellability optional parameter is true, then the coroutine is suspended, but it is not cancellable until CancellableContinuation.initCancellability is invoked.

See suspendAtomicCancellableCoroutine for suspending functions that need atomic cancellation.