Coroutines: Dispatchers.IO only for blocking IO?

Hi,

I have a code which combines blocking IO and async HTTP requests. Currently I enclose blocking IO inside

withContext(Dispatchers.IO) {
  // use InputStreams coming from async HTTP requests
  // eg. ZipInputStream(resp.content.toInputStream()).nextEntry
}

but it’s a lot of work and you can easily forget to do it. Why not use Dispatchers.IO for both blocking IO and async HTTP requests?

I’m not fully sure of what you’re asking. What is “a lot of work”? Adding withContext(Dispatchers.IO) around such blocks?

In general I don’t think there’s specifically wrong in using Dispatchers.IO for both sync and async IO.

I’m not fully sure of what you’re asking. What is “a lot of work”? Adding withContext(Dispatchers.IO) around such blocks?

IMO yes, if you want to do it with a fine granularity (ie. wrapping every call instead of bigger blocks).

In general I don’t think there’s specifically wrong in using Dispatchers.IO for both sync and async IO.

Ok, thanks.