Hi. Will the code inside `async {}` block execute ...
# coroutines
h
Hi. Will the code inside
async {}
block execute even if I didn't call
await
on it? Shouldn't it actually start executing when I call
await
? Or
await
is just that it awaits for the execution to finish and doesn't mean that it shouldn't execute without await? Just without
await
it becomes redundant and behaves like
launch
not paying attention to the return type)
s
Yes, by default the code inside
async
will start right away. There is an optional parameter you can pass to the
async
function if you want to change that, though.
🙌 1
await
is just there so you can get the result (or exception, in case of failure). If you don't need a result, you're correct that you can just use
launch
.
🙌 1
d
There is an optional parameter you can pass to the
async
function if you want to change that, though.
It's likely that you don't, though: https://github.com/Kotlin/kotlinx.coroutines/issues/4202 If you do, please let us know in the comments!