Shmuel Rosansky [G]
01/08/2020, 10:32 PMoctylFractal
01/08/2020, 10:34 PMsuspend
language feature itself does not know about cancellation, that's strictly a concept from the coroutines library. so it does not check for cancellation.
many (but not all) functions provided by the coroutines library do check for cancellation, and the docs will say if they do or notoctylFractal
01/08/2020, 10:35 PMShmuel Rosansky [G]
01/08/2020, 10:39 PMShmuel Rosansky [G]
01/08/2020, 10:39 PMShmuel Rosansky [G]
01/08/2020, 10:40 PMoctylFractal
01/08/2020, 10:40 PMwithContext
is one of them: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/with-context.htmloctylFractal
01/08/2020, 10:41 PMNote that the result of withContext invocation is dispatched into the original context in a cancellable way, which means that if the original coroutineContext, in which withContext was invoked, is cancelled by the time its dispatcher starts to execute the code, it discards the result of withContext and throws CancellationException.
Shmuel Rosansky [G]
01/08/2020, 10:42 PMoctylFractal
01/08/2020, 10:42 PMwithContext(IO)
?octylFractal
01/08/2020, 10:43 PMwithContext
, in short withContext
checks for cancellation before it returnsShmuel Rosansky [G]
01/08/2020, 10:43 PMShmuel Rosansky [G]
01/08/2020, 10:44 PMoctylFractal
01/08/2020, 10:45 PMoctylFractal
01/08/2020, 10:45 PMThe method may throw a CancellationException if the current job was cancelled externally
Shmuel Rosansky [G]
01/08/2020, 10:52 PM