https://kotlinlang.org logo
#coroutines
Title
# coroutines
o

Olekss

01/29/2018, 7:22 PM
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

r4zzz4k

01/29/2018, 7:54 PM
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

Olekss

01/29/2018, 8:02 PM
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

AJ Alt

01/29/2018, 8:25 PM
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

dave08

01/29/2018, 8:55 PM
run
was changed to
withContext
, they probably didn't catch all the places it's mentioned in the docs...
g

gildor

01/30/2018, 12:38 AM
@Olekss you have such hook: CancellableContinuation.invokeOnCompletion
7 Views