@@ -116,8 +116,11 @@ public func withDiscardingTaskGroup<GroupResult>(
116
116
/// be the case with a ``TaskGroup``.
117
117
///
118
118
/// ### Cancellation behavior
119
- /// A task group becomes cancelled in one of two ways: when ``cancelAll()`` is
120
- /// invoked on it, or when the ``Task`` running this task group is cancelled.
119
+ /// A discarding task group becomes cancelled in one of the following ways:
120
+ ///
121
+ /// - when ``cancelAll()`` is invoked on it,
122
+ /// - when an error is thrown out of the `withThrowingDiscardingTaskGroup(...) { }` closure,
123
+ /// - when the ``Task`` running this task group is cancelled.
121
124
///
122
125
/// Since a `TaskGroup` is a structured concurrency primitive, cancellation is
123
126
/// automatically propagated through all of its child-tasks (and their child
@@ -431,8 +434,28 @@ public func withThrowingDiscardingTaskGroup<GroupResult>(
431
434
/// be the case with a ``TaskGroup``.
432
435
///
433
436
/// ### Cancellation behavior
434
- /// A task group becomes cancelled in one of two ways: when ``cancelAll()`` is
435
- /// invoked on it, or when the ``Task`` running this task group is cancelled.
437
+ /// A throwing discarding task group becomes cancelled in one of the following ways:
438
+ ///
439
+ /// - when ``cancelAll()`` is invoked on it,
440
+ /// - when an error is thrown out of the `withThrowingDiscardingTaskGroup(...) { }` closure,
441
+ /// - when the ``Task`` running this task group is cancelled.
442
+ ///
443
+ /// But also, and uniquely in *discarding* task groups:
444
+ /// - when *any* of its child tasks throws.
445
+ ///
446
+ /// The group becoming cancelled automatically, and cancelling all of its child tasks,
447
+ /// whenever *any* child task throws an error is a behavior unique to discarding task groups,
448
+ /// because achieving such semantics is not possible otherwise, due to the missing `next()` method
449
+ /// on discarding groups. Accumulating task groups can implement this by manually polling `next()`
450
+ /// and deciding to `cancelAll()` when they decide an error should cause the group to become cancelled,
451
+ /// however a discarding group cannot poll child tasks for results and therefore assumes that child
452
+ /// task throws are an indication of a group wide failure. In order to avoid such behavior,
453
+ /// use a ``DiscardingTaskGroup`` instead of a throwing one, or catch specific errors in
454
+ /// operations submitted using `addTask`
455
+ ///
456
+ /// Since a `TaskGroup` is a structured concurrency primitive, cancellation is
457
+ /// automatically propagated through all of its child-tasks (and their child
458
+ /// tasks).
436
459
///
437
460
/// Since a `TaskGroup` is a structured concurrency primitive, cancellation is
438
461
/// automatically propagated through all of its child-tasks (and their child
@@ -524,6 +547,7 @@ public struct ThrowingDiscardingTaskGroup<Failure: Error> {
524
547
#endif
525
548
}
526
549
550
+ ///
527
551
public var isEmpty : Bool {
528
552
_taskGroupIsEmpty ( _group)
529
553
}
0 commit comments