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

voddan

10/17/2018, 12:19 PM
What is supposed to happen if
async {}
block throws an exception, but the result is never used? I get different behaviour in playground and InteliJ https://pl.kotl.in/rkOAdiNiQ
Copy code
suspend fun main() {
    coroutineScope {
        val x = async { null!! }
    }
    
    println("end")
}
g

gildor

10/17/2018, 1:03 PM
What is result that you expect. Behavior of playground the same as should be for async according to docs
Await encapsulate exception and do not throwing it until someone calls await
v

voddan

10/17/2018, 1:12 PM
@gildor I use coroutines_version = '0.30.2-eap13' and this example propagates the exception up into my bash
d

Daniel Tam

10/17/2018, 2:40 PM
I believe this behaviour changed recently to be the same as launch, because otherwise it's painful to await multiple async calls correctly while still stopping if an error occurs anywhere
v

voddan

10/17/2018, 3:50 PM
@Daniel Tam do you know where could I read about it?
v

voddan

10/17/2018, 3:58 PM
👍🏼
g

gildor

10/18/2018, 1:11 AM
Ahhh, sure, coroutineScope will throw an error anyway, because failed async will cancel coroutineScope
v

voddan

10/18/2018, 8:50 AM
BTW, how do I revert to the old behaviour? I don't care about the error until I need the result
g

gildor

10/18/2018, 9:38 AM
7 Views