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

elizarov

10/18/2018, 8:45 AM
You cannot cancel blocking work, unless it is cooperates with cancellation. Cancellation is always cooperative.
s

SUPERCILEX

10/18/2018, 2:36 PM
So how do we deal with blocking calls?
Should we wrap them in some sort of future and use the cancelable continuation?
e

elizarov

10/18/2018, 2:46 PM
Wrapping the into a future would not help you to cancel them. Just don’t
That is one big reason not do blocking work.
But if you have to (like JDBC drivers, for example), just live with the fact they cannot be cancelled
s

SUPERCILEX

10/18/2018, 2:56 PM
Alright, not quite what I'd hoped but it makes sense
e

elizarov

10/18/2018, 3:10 PM
Now, some limited subsets for blocking APIs have api-specific means of cancellation. For example, if you do blocking socket IO, the closing the socket aborts blocked operation. For those cases you can implement your own API-specific cancellable solution. But in general, blocking APIs are simply non-cancellable
s

SUPERCILEX

10/18/2018, 3:23 PM
Good point
e

elizarov

10/18/2018, 3:28 PM
suspendCancellableCoroutine
👍 1
3 Views