Do I need to mention the coroutine dispatcher while working with Retrofit? #4024
-
Type: Question I'm working with Retrofit and coroutines, and I'm wondering whether I need to explicitly mention the coroutine dispatcher when making network requests. I've read that Retrofit is designed to handle background tasks using coroutines, so I'm not sure if explicitly specifying the dispatcher is necessary. Can anyone provide clarification on this matter? Is it recommended to specify the coroutine dispatcher when using Retrofit, or is it handled automatically by the library? I've tried searching for the answer online, but I haven't found a definitive explanation. I'm hoping someone from the Retrofit team or community can shed some light on this issue. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There is nowhere for you to provide a dispatcher/context and that's by design. Retrofit supports exposing suspend APIs. Those execute asynchronously in relation to the caller. Where they execute is mostly irrelevant, but it's on the OkHttp Dispatcher which you don't really need to know about. |
Beta Was this translation helpful? Give feedback.
There is nowhere for you to provide a dispatcher/context and that's by design.
Retrofit supports exposing suspend APIs. Those execute asynchronously in relation to the caller. Where they execute is mostly irrelevant, but it's on the OkHttp Dispatcher which you don't really need to know about.