Hi! I see this piece of code in a library. is the ...
# coroutines
c
Hi! I see this piece of code in a library. is the function
suspendCancellableCoroutine <Nothing> {}
needed ? For me is just an empty call
Copy code
class 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()
        }
    }
}
s
This is a way of suspending indefinitely and code that follows it will never be executed. It can only be cancelled (normally or with an error/exception). If that happens, the onDispose is called.
👍 1
1
l
BTW, it should be replaced with
awaitCancellation()
now that it made it into kotlinx.coroutines stable API.
1
c
🙌 This new API give more context about his intention