Skip to content

Add ability to specify cancellation propagation strategy when creating a Job/Deferred #3409

@dovchinnikov

Description

@dovchinnikov

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
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions