zak.taccardi
09/10/2020, 8:43 PMJob
, how can I fail it with an exception? I want to cancel it abnormally so its parent failsZach Klippenstein (he/him) [MOD]
09/10/2020, 8:46 PMCancellationException
, and cancellation is just failure with an exception. They all use the same mechanism, just different words to describe different special cases.zak.taccardi
09/10/2020, 8:48 PMzak.taccardi
09/10/2020, 8:48 PMprivate fun Job.fail() {
TODO("make this job fail with an exception")
}
Zach Klippenstein (he/him) [MOD]
09/10/2020, 8:49 PMjob.cancel(RuntimeException("fail"))
?zak.taccardi
09/10/2020, 8:49 PMzak.taccardi
09/10/2020, 8:50 PMfun cancel(cause: CancellationException? = null)
Zach Klippenstein (he/him) [MOD]
09/10/2020, 8:52 PMjob.cancel(CancellationException(RuntimeException("fail")))
zak.taccardi
09/10/2020, 8:56 PMzak.taccardi
09/10/2020, 8:58 PMprivate fun CoroutineScope.fail() {
try {
runBlocking(this.coroutineContext) {
@Suppress("RedundantAsync", "IMPLICIT_NOTHING_TYPE_ARGUMENT_IN_RETURN_POSITION")
async(this@fail.coroutineContext) {
error("bad things!!")
}
.await()
}
} catch (exception: IllegalStateException) {
}
}
Zach Klippenstein (he/him) [MOD]
09/10/2020, 9:02 PMZach Klippenstein (he/him) [MOD]
09/10/2020, 9:02 PMZach Klippenstein (he/him) [MOD]
09/10/2020, 9:02 PMzak.taccardi
09/10/2020, 9:02 PMzak.taccardi
09/10/2020, 9:03 PMZach Klippenstein (he/him) [MOD]
09/10/2020, 9:04 PMzak.taccardi
09/10/2020, 9:07 PMjob.fail()
function rather than job.cancel()
zak.taccardi
09/10/2020, 9:08 PM