Usually you just invoke blocking operation and it works fine. The problem arises then you have multiple blocking calls running simultaneously. They can exhaust CommonPool
and block completely. I see three possibility here:
- If operations are fast and you are sure that they won’t block forever, you can call them inside coroutines.
- If operations are long, but you have only few of them, you can use custom
CoroutineContext
with increased number of parallel threads. - If you have a large number of those blocking operations, you should just good old executor. If you want to evaluate the result, you can create a
Channel
and send results to it.