Does taskGroup.cancelAll() require active co-operation to finish properly?

And now the question morphs into: "OK, I canceled one of my started tasks, and that task is blocked waiting on a checkedContinuation. So why didn't it return from await checkedContinuation when I explicitly canceled its task, using taskGroup.cancelAll()?"

Because cancellation is cooperative, i.e. a Task always requires whatever it is executing to explicitly check for cancellation, unwind its stack and return before CancellationError() can be thrown by the continuation.
Depending on your use case, you may need to wrap your continuation with withTaskCancellationHandler() so that you can signal your subsystem to stop what it's doing and return early.

3 Likes