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
streetsofboston
05/11/2021, 6:01 PM
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
louiscad
05/11/2021, 10:23 PM
BTW, it should be replaced with
awaitCancellation()
now that it made it into kotlinx.coroutines stable API.
✅ 1
c
carbaj0
05/12/2021, 4:01 AM
🙌 This new API give more context about his intention