jean
02/08/2021, 10:22 AMprivate 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?wasyl
02/08/2021, 10:27 AMjean
02/08/2021, 10:32 AMwasyl
02/08/2021, 11:05 AMfindHeavyWorkToExecute()?.invoke()
returns null?
This simple test doesn’t print anything:
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
jean
02/08/2021, 11:13 AM