Second, semi-related question.. is there any way at all to access the coroutine context inside an okhttp3 interceptor? or any way at all to have the coroutine context and the request object in the same.. context?
r
Robert Williams
06/20/2024, 4:06 PM
Unfortunately Interceptors aren’t suspend funs so they don’t have a coroutine context. If you need to call suspend funs you can use runBlocking but the context will be different and unrelated to the outer context
a
abbic
06/20/2024, 4:19 PM
i figured, might it be at all possible with call adapters then? otherwise the only alternative id have is to add a parameter to the retrofit api interface and pass my data from the coroutine context manually
abbic
06/20/2024, 4:21 PM
that is, add a parameter to every individual api call. i want to add a header to all calls made within a specific coroutine context so id like as generic a solution as possible instead of one that will need constant maintenance going forward
r
Robert Williams
06/20/2024, 4:44 PM
suspend support works on top of the Call API so Call also isn’t coroutine-aware (none of Retrofit’s APIs are because they need to work with Java). Your best bet is probably to implement some common wrapper class/ method which works above Retrofit, or switch to a library with better coroutine support (maybe ktor)?
a
abbic
06/20/2024, 5:40 PM
trying out ktor is real attractive but i think too much work for what i want, i work in a large project 😅. wrapper also sounds it might be a lot of work, so my plans might be dead in the water 😮💨