<https://twitter.com/SUPERCILEX/status/10527576723...
# coroutines
e
You cannot cancel blocking work, unless it is cooperates with cancellation. Cancellation is always cooperative.
s
So how do we deal with blocking calls?
Should we wrap them in some sort of future and use the cancelable continuation?
e
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
Alright, not quite what I'd hoped but it makes sense
e
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
Good point
e
suspendCancellableCoroutine
👍 1