-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Docs][Concurrency] TaskGroup docs: waitForAll (non-)cancellation #63956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -616,6 +616,35 @@ public struct ThrowingTaskGroup<ChildTaskResult: Sendable, Failure: Error> { | |
} | ||
|
||
/// Wait for all of the group's remaining tasks to complete. | ||
/// | ||
/// If any of the tasks throw, the *first* error thrown is captured | ||
/// and re-thrown by this method although the task group is *not* cancelled | ||
/// when this happens. | ||
/// | ||
/// ### Cancelling the task group on first error | ||
/// | ||
/// If you want to cancel the task group, and all "sibling" tasks, | ||
/// whenever any of child tasks throws an error, use the following pattern instead: | ||
/// | ||
/// ``` | ||
/// while !group.isEmpty { | ||
/// do { | ||
/// try await group.next() | ||
/// } catch is CancellationError { | ||
/// // we decide that cancellation errors thrown by children, | ||
/// // should not cause cancellation of the entire group. | ||
/// continue; | ||
/// } catch { | ||
/// // other errors though we print and cancel the group, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not really print, I guess. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks will add |
||
/// // and all of the remaining child tasks within it. | ||
/// group.cancelAll() | ||
/// } | ||
/// } | ||
/// assert(group.isEmpty()) | ||
/// ``` | ||
/// | ||
/// - Throws: The *first* error that was thrown by a child task during draining all the tasks. | ||
/// This first error is stored until all other tasks have completed, and is re-thrown afterwards. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only instance of waitForAll which has such special semantics. Discarding groups don't have this API, nor can they use |
||
@_alwaysEmitIntoClient | ||
public mutating func waitForAll() async throws { | ||
var firstError: Error? = nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👽
;