I I've been brooding over this for a while, and I still think that TaskGroup
should cancels all of it's child tasks at the end of the body
regardless of how it finishes (throwing vs non-throwing).
Firstly, note that we can override the default behaviour by calling group.cancellAll()
or while true { await group.next() }
, so it's more of the preference and has no impact on the expressibility.
There are a few reasons I prefer cancellation for all exits, even if the body
doesn't throw.
-
It makes the system much easier to explain (unused child tasks are cancelled).
-
It would help the task group finishes earlier if the child tasks are cooperative, which is roughy the point of the cancellation.
-
Furthermore, I believe it's more common for unused child tasks to be easily discardable and has no side effect.
Again, if it is important that the task finishes, it's more likely that
async {}
orTask.detach
are better for such jobs.