```private val supervisor = SupervisorJob() privat...
# coroutines
j
Copy code
private val supervisor = SupervisorJob()
private val coroutineScope = CoroutineScope(coroutineContext + supervisor)
...
fun onEvent(event: MyEvent) {
    coroutineScope.launch {
        val data = findHeavyWorkToExecute()?.invoke()
            ?: throw Exception(currentState, event)

        someMoreWork(data)
     }
}
I’m want
someMoreWork()
to be executed only if the lambda returned by
findHeavyWorkToExecute()
is not null and its execution does not fail. But when I test this
someMoreWork()
is called even though the
throw
statement occurs. What am I suppose to change there?
w
Do you use new JVM IR backend perhaps?
j
no I didn’t updated yet
w
Are you sure
findHeavyWorkToExecute()?.invoke()
returns null? This simple test doesn’t print anything:
Copy code
private val coroutineScope = CoroutineScope(SupervisorJob())

@Test
fun test(): Unit = runBlocking {
    coroutineScope.launch {
        val data = findSomeHeavyWork() ?: throw Exception()

        println("after stuff")
    }

    delay(1000)
}

fun findSomeHeavyWork(): Unit? = null
j
you are right, I just realized it was the lambda execution that was failing inside a try/catch and returning an error rather than the lambda being null 🤦 thanks for the help!
👍 1