I just wanted to check my understanding of the following, at it seems a bit counterintuitive to me, but how can a child task be awaited after it is implicitly cancelled, as stated in SE-0304? It seems a bit counterintuitive that a child task would be awaited after it is cancelled. Since, to me, the child task has already been cancelled, so how can it be awaited?
Further, SE-304 states that a task group will wait until all child tasks have completed before returning if the closure passed to withTaskGroup exits without completing its child tasks - this logic seems a bit cyclical to me. Can someone please elaborate on what this means?
Cancellation is just a boolean flag to notify the task that it should stop as soon as possible, but it's up to the task to actually stop executing — the runtime does not "shut it down" forcefully.
Meanwhile, awaiting a task means suspending until it actually has completed running, regardless of whether it finished normally or through cancellation — this "fork-join" behavior is the promise of structured concurrency, guaranteeing that the rest of the logic observes the result of the children.