is there any point to doing something like `lauch ...
# coroutines
p
is there any point to doing something like
lauch { val result = async { doStuff() }.await() }
, assuming
doStuff()
is a suspend fun? or would it make more sense to simply call
doStuff()
inside the launch block without
async
?
z
just call
doStuff()
inside
launch
, that
async
isn’t doing anything.
p
i figured as much. where is async best applied, then?
i guess when you have multiple suspend functions that you want to wait for simultaneously, and/or they are long-running?
👌 2
j
async
is used when you want to run code in parallel
So, if you wanted to issue two network requests at the same time, then wait for both to complete, you could start them both in their own
async
blocks, then await on both of the returned Deferreds
p
sounds right
most of my async knowledge comes from nodejs callbacks, so i still think that way heavily
d
async
shouldnt be user very often at all, as a generale type of thumb.
withContext
should commonly be used instead, when you invoke
await
immediately anyway