sorry about a possibly stupid question but is this...
# coroutines
o
sorry about a possibly stupid question but is this:
val x = (async { foo() }).await()
ever different from just
val x = foo()
?
e
Copy code
var i = 0
launch { i++ }
val x = i

var j = 0
launch { j++ }
val y = async { j }.await()
x == 0 && y == 1
(not guaranteed, but likely in a single threaded dispatcher)
o
so does that mean the
async
call is a suspension point?
u
await
is
o
ah indeed
but if
foo()
in my example is a
suspend fun
does it make any difference in that case?
u
yes, even in a single threaded dispatcher you can have state changed by other coroutines at each suspension point
o
i mean does wrapping the call in
async
make any difference? the call to
foo()
is also a suspension point right?
u
depends on foo. If foo suspends it is. if foo does not suspend it’s not. Calling this
foo
will not suspend:
suspend fun foo(): Int { return 1 }
w
iiuc it’s a possible suspension point, it’ll not suspend unless you suspend inside foo
o
i see, thanks