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

Mohamed Ibrahim

02/18/2020, 10:43 PM
how do I switch between dispatchers using
async
and
await
?
z

Zach Klippenstein (he/him) [MOD]

02/18/2020, 10:56 PM
You can pass a dispatcher to
async
, that dispatcher will be used to run the block.
await
uses the dispatcher in the current context, which you can change with
withContext
.
m

Mohamed Ibrahim

02/18/2020, 10:57 PM
nice thank u
z

Zach Klippenstein (he/him) [MOD]

02/19/2020, 12:48 AM
To clarify,
await
doesn't really "use" a dispatcher, it just suspends the current coroutine.
👍 1
b

bdawg.io

02/19/2020, 1:52 AM
Yeah, as he's describing
await
will receive the value in the current context, so there MAY be benefits if you have to utilize that value inside that context as well.
👍 1
4 Views