gildor
06/24/2019, 6:04 AMcall.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 likerunBlocking will work correctly. Not 100% sure how ThreadContextElement works, but as I understand it also should work, this is the whole point of this contextwork correctly with itrunBlocking and ThreadContextElement
hmole
06/24/2019, 6:58 AMrunBlocking
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.gildor
06/24/2019, 7:01 AMgildor
06/24/2019, 7:01 AMMy problem with enqueue andWhy?is that I get a resource deadlockrunBlocking
gildor
06/24/2019, 7:01 AMI 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
hmole
06/24/2019, 7:12 AMThreadLocalElement
. 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.