Is it ok to dump all thread blocking tasks into the IO dispatcher?

I’m working on a project that makes a lot of net calls and of course it has to stay hanged waiting. Is it ok to wrap every call with withContext(IO)? Where is the catch :thinking:?


Yes you can do this, kotlinx.coroutines will allocated more threads if the pool is busy and reuse the ones that are free. This is not a good practice though and I would advise you to use non-blocking networking (using java NIO for example ) for a better scalability.

The catch is that if you do hundreds of blocking call at once, you will end up with hundreds of threads, leading to bad performances and a high memory usage.

Hope this helps :slight_smile:

Unfortunately the calls are made by libraries. I managed to wrap whatever callback with a manually suspended-resumed context