<@U8Y2VH5AB> `call.execute()` is bad idea, it make...
# squarelibraries
g
@hmole
call.execute()
is bad idea, it make request non cancellable, better to use call.await() without any additional async wrappers. And if someone really want to share threads between coroutine dispatchers and OkHttp it’s better to write some custom OkHttp dispatcher, but not sure that it worth it
things like
runBlocking and ThreadContextElement
work correctly with it
runBlocking will work correctly. Not 100% sure how ThreadContextElement works, but as I understand it also should work, this is the whole point of this context
h
My problem with enqueue and
runBlocking
is that I get a resource deadlock, because I expected okhttp request to run in the same thread(which wasn't the case).
ThreadContextElement
definitely doesn't work, because I tested it.
g
How do you use ThreadContextElement?
My problem with enqueue and
runBlocking
is that I get a resource deadlock
Why?
I expected okhttp request to run in the same thread(which wasn’t the case).
Which sounds like bad assumption in general and some problem in your codse
h
I meant
ThreadLocalElement
. It doesn't work because thread gets switched bypassing coroutine dispatcher, and so the value doesn't get updated. Regarding my
runBlocking
case - I open a transaction and run several requests for data. Each of those requests does additional database queries(for token retrival). And so I get a deadlock, when I try to access db from another thread, while there is a transaction ongoing.