I need a CompletableJob (and/or CompletableDeferred) such that:
- its parent propagates cancellation down to it;
- its parent waits for completion of it;
- it does not cancel its parent on failure regardless of whether a parent is a supervisor or not.
Currently this works, but it's ugly (pseudocode):
val intermediateSupervisor = SupervisorJob(parent = coroutineContext.job)
val child = Job(parent = intermediateSupervisor)
try {
runWithChildAndCompleteIt(child) { ... }
}
finally {
intermediateSupervisor.complete()
}
fun runWithChildAndCompleteIt(job: CompletableJob) {
try {
...
child.complete()
}
catch (t: Throwable) {
child.completeExceptionally(t)
throw t
}
}