Sean McQuillan
May 25, 2019 · 1 min read

Ah yes this is correct — if you make any blocking I/O like Call.execute() you will need to switch to a dispatcher optimized for network I/O such as Dispatchers.IO.

In the next release of Retrofit2, suspend functions will be supported directly on service methods.

Today, the best stable release option for integrating retrofit with coroutines is to use the retrofit2-kotlin-coroutine-adapter which allows you to use Deferred as a service method result. If you don’t want a dependency you can also use suspendCancellableCoroutine to create an extension function on Call called await() that uses enqueue internally.

Sean McQuillan

Written by

Android Developer Advocate @Google

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade