Allan Wang
01/23/2019, 4:27 AMsupervisorScope
and try catch it. However, it still doesn’t stop the cancellation of every other job, despite the main context already being a supervisorDico
01/23/2019, 9:08 AMNonCancellable
to your contextAllan Wang
01/23/2019, 2:41 PMNonCancellable
still allow job.cancel()
?
My use case:
launch {
// a
suspendFunB()
// c
}
launch {
// d
}
Suspend B may crash, but I always want a
and c
to execute. I also want d
to always execute without being affected by the previous launch. If the parent scope is cancelled, I’d like everything to cancel.
Should NonCancellable
be around suspendFunB
or the first launch?Dico
01/24/2019, 8:33 PMNonCancellable
means the coroutine ignores cancellation from job.cancel()
. So I would do:
launch(NonCancellable) {
// a
try {
suspendFunB()
} finally {
// c
}
}
Allan Wang
01/24/2019, 10:23 PMjob.cancel()
is called.