When should one use async-await Vs withContext
# coroutines
r
When should one use async-await Vs withContext
m
Calling
withContext
is like doing
await
immediately on the
Deferred
from
async
. Use
async
if you want to do something else while waiting for the
Deferred
to complete.
👍🏼 2
l
Not exactly. A crash in the
async
block will cancel the parent scope.
withContext
will only throw and will let you catch without an extra scope.
r
Makes sense , Thanks!
Ahhhhh
I see , thanks @louiscad!
So depending how you want your cancellation will be how you choose one from the other
So depending how you want your cancellation will be how you choose one from the other
l
@rkeazor Nope, I'll always using
withContext
if I need to change the dispatcher. The only exception might be using
flowOn
to make a flow run on a specific dispatcher.
async
is for parallelization in a coroutine.
1
👍 1
d
cough concurrency not parallelism cough
l
I see it as local parallelism. The issue is the connotation of these words that I want to avoid. Concurrency is more loaded of it IMHO.