Hey somehow I can't find that run {} coroutine bui...
# coroutines
o
Hey somehow I can't find that run {} coroutine builder doc and stuff Looking at : https://github.com/Kotlin/kotlinx.coroutines/blob/master/core/kotlinx-coroutines-core/README.md
r
Do you mean
run
from this snippet?
run(NonCancellable) {...}
If so,
NonCancellable
doc mentions
withContext(NonCancellable) { ... }
instead of that: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/-non-cancellable/index.html Probably a typo.
o
Hmm...
Okay. Then it looks like I need cancellable one - I Suppose "launch" is my case
But what if I cancel launched coroutine which contains some blocking code - like server socket waiting for incoming messages? Do I have chances - some hooks - to clean up my socket if some evil force cancels my launched coroutine?
a
Cancellation is cooperative. IIUC, cancellation is implemented by having the suspending function check if it's cancelled at each suspension point, and throw a
CancellationException
if so. So you can clean up with finally etc.
d
run
was changed to
withContext
, they probably didn't catch all the places it's mentioned in the docs...
g
@Olekss you have such hook: CancellableContinuation.invokeOnCompletion