@@ -488,15 +488,17 @@ public struct TaskGroup<ChildTaskResult: Sendable> {
488
488
489
489
/// Cancel all of the remaining tasks in the group.
490
490
///
491
- /// After cancellation,
492
- /// any new results from the tasks in this group
493
- /// are silently discarded.
494
- ///
495
491
/// If you add a task to a group after canceling the group,
496
492
/// that task is canceled immediately after being added to the group.
497
493
///
498
- /// This method can only be called by the parent task that created the task
499
- /// group.
494
+ /// Immediately cancelled child tasks should therefore cooperatively check for and
495
+ /// react to cancellation, e.g. by throwing an `CancellationError` at their
496
+ /// earliest convenience, or otherwise handling the cancellation.
497
+ ///
498
+ /// There are no restrictions on where you can call this method.
499
+ /// Code inside a child task or even another task can cancel a group,
500
+ /// however one should be very careful to not keep a reference to the
501
+ /// group longer than the `with...TaskGroup(...) { ... }` method body is executing.
500
502
///
501
503
/// - SeeAlso: `Task.isCancelled`
502
504
/// - SeeAlso: `TaskGroup.isCancelled`
@@ -929,6 +931,7 @@ public struct ThrowingTaskGroup<ChildTaskResult: Sendable, Failure: Error> {
929
931
///
930
932
/// At the start of the body of a `withThrowingTaskGroup(of:returning:body:)` call,
931
933
/// the task group is always empty.
934
+ ///
932
935
/// It's guaranteed to be empty when returning from that body
933
936
/// because a task group waits for all child tasks to complete before returning.
934
937
///
@@ -939,15 +942,17 @@ public struct ThrowingTaskGroup<ChildTaskResult: Sendable, Failure: Error> {
939
942
940
943
/// Cancel all of the remaining tasks in the group.
941
944
///
942
- /// After cancellation,
943
- /// any new results or errors from the tasks in this group
944
- /// are silently discarded.
945
- ///
946
945
/// If you add a task to a group after canceling the group,
947
946
/// that task is canceled immediately after being added to the group.
948
947
///
948
+ /// Immediately cancelled child tasks should therefore cooperatively check for and
949
+ /// react to cancellation, e.g. by throwing an `CancellationError` at their
950
+ /// earliest convenience, or otherwise handling the cancellation.
951
+ ///
949
952
/// There are no restrictions on where you can call this method.
950
- /// Code inside a child task or even another task can cancel a group.
953
+ /// Code inside a child task or even another task can cancel a group,
954
+ /// however one should be very careful to not keep a reference to the
955
+ /// group longer than the `with...TaskGroup(...) { ... }` method body is executing.
951
956
///
952
957
/// - SeeAlso: `Task.isCancelled`
953
958
/// - SeeAlso: `ThrowingTaskGroup.isCancelled`
0 commit comments