# Coroutines: Dispatchers.IO only for blocking IO?

**URL:** <https://discuss.kotlinlang.org/t/coroutines-dispatchers-io-only-for-blocking-io/18370>\
**Category:** Support\
**Created:** [July 8, 2020, 2:11pm UTC](https://discuss.kotlinlang.org/t/coroutines-dispatchers-io-only-for-blocking-io/18370 "2020-07-08T14:11:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![radekm](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/radekm/32/7733_2.png) [@radekm](https://discuss.kotlinlang.org/u/radekm)\
**Post date:** [July 8, 2020, 2:11pm UTC](https://discuss.kotlinlang.org/t/coroutines-dispatchers-io-only-for-blocking-io/18370/1 "2020-07-08T14:11:33Z")

</div>

Hi,

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

```kotlin
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?

---

<div class="post-metadata">

**Author:** ![al3c](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@al3c](https://discuss.kotlinlang.org/u/al3c)\
**Post date:** [July 8, 2020, 3:33pm UTC](https://discuss.kotlinlang.org/t/coroutines-dispatchers-io-only-for-blocking-io/18370/2 "2020-07-08T15:33:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![radekm](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/radekm/32/7733_2.png) [@radekm](https://discuss.kotlinlang.org/u/radekm)\
**Post date:** [July 8, 2020, 6:50pm UTC](https://discuss.kotlinlang.org/t/coroutines-dispatchers-io-only-for-blocking-io/18370/3 "2020-07-08T18:50:34Z")

</div>

> 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.
