carbaj0
05/11/2021, 10:25 AMclass ProduceStateScopeImpl<T>(
state: MutableState<T>,
override val coroutineContext: CoroutineContext
) : ProduceStateScope<T>, MutableState<T> by state {
override suspend fun awaitDispose(onDispose: () -> Unit): Nothing {
try {
suspendCancellableCoroutine<Nothing> { }
} finally {
onDispose()
}
}
}
Why suspendCancellableCoroutine<Nothing> { }
is being executed?Zach Klippenstein (he/him) [MOD]
05/11/2021, 1:27 PMawaitDispose
?Zach Klippenstein (he/him) [MOD]
05/11/2021, 1:28 PMAdam Powell
05/11/2021, 1:55 PMAdam Powell
05/11/2021, 1:55 PMawaitClose
carbaj0
05/11/2021, 4:25 PMcarbaj0
05/11/2021, 4:25 PMZach Klippenstein (he/him) [MOD]
05/11/2021, 5:09 PMsuspendCancellableCoroutine
not to be executed?carbaj0
05/11/2021, 6:19 PMcarbaj0
05/11/2021, 6:19 PMcarbaj0
05/11/2021, 6:19 PMpublic suspend inline fun <T> suspendCancellableCoroutine(
crossinline block: (CancellableContinuation<T>) -> Unit
): T =
suspendCoroutineUninterceptedOrReturn { uCont ->
val cancellable = CancellableContinuationImpl(uCont.intercepted(), resumeMode = MODE_CANCELLABLE)
/*
* For non-atomic cancellation we setup parent-child relationship immediately
* in case when `block` blocks the current thread (e.g. Rx2 with trampoline scheduler), but
* properly supports cancellation.
*/
cancellable.initCancellability()
block(cancellable)
cancellable.getResult()
}
carbaj0
05/11/2021, 6:23 PMcoroutineContext.cancel ()
or something like that ๐
Adam Powell
05/11/2021, 7:57 PMcarbaj0
05/12/2021, 3:41 AMawaitCancellation()
carbaj0
05/12/2021, 3:43 AM/**
* Suspends until cancellation, in which case it will throw a [CancellationException].
*
* This function returns [Nothing], so it can be used in any coroutine,
* regardless of the required return type.
*/
public suspend fun awaitCancellation(): Nothing = suspendCancellableCoroutine {}
carbaj0
05/12/2021, 3:43 AMAdam Powell
05/12/2021, 5:02 AMawaitDispose
scoped method before awaitCancellation
came in ๐