https://kotlinlang.org logo
#coroutines
Title
# coroutines
j

joao.alves

12/19/2018, 10:21 PM
that’s the thing I don’t. If I remove all the
withContext
and leave the
launch
as it is, and with the base context defined as Main + job it works just fine
d

dave08

12/20/2018, 3:57 AM
Because you're probably using a library that originally returns a callback (with its own thread pool for running the request) and await seems to be adapting that callback using
suspendCallableCoroutine { }
, which will suspend until the callback is called. Then you don't need
withContext
at all.
a

Abdul Kadir

12/20/2018, 5:46 AM
launch does not block the main thread, that's why you don't get an exception
d

dave08

12/20/2018, 7:25 AM
Not true if launch uses the Main dispatcher and you run blocking code on it...
For real blocking code withContext with IO or Default or custom dispatcher is needed.
✔️ 1
4 Views