Skip to content

[Docs][Concurrency] Fix documentation about cancellation, copy docs to a few methods #63960

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

Merged
merged 5 commits into from
Feb 28, 2023

Conversation

ktoso
Copy link
Contributor

@ktoso ktoso commented Feb 28, 2023

While adding documentation in #63956 I noticed that some of the docs are wrong, e.g. the docs mentioned that "cancelled tasks are silently discarded" which isn't true, they run as usual.

This does a cleanup pass wrt. cancellation semantics and makes it clearer and correct.
Added docs in a few spots where we didn't copy them over; sadly this API is riddled with tons of overloads which makes such mistakes possible.

@@ -262,7 +258,7 @@ public struct TaskGroup<ChildTaskResult: Sendable> {
/// Adds a child task to the group.
///
/// - Parameters:
/// - overridingPriority: The priority of the operation task.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong param name

@@ -491,15 +487,17 @@ public struct TaskGroup<ChildTaskResult: Sendable> {

/// Cancel all of the remaining tasks in the group.
///
/// After cancellation,
/// any new results from the tasks in this group
/// are silently discarded.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't true, cancelled tasks run as usual and can be collected.

FYI @amartini51 in case we used this assumption somewhere else in some docs?

/// A discarding task group eagerly discards and releases its child tasks as
/// soon as they complete. This allows for the efficient releasing of memory used
/// by those tasks, which are not retained for future `next()` calls, as would
/// be the case with a ``TaskGroup``.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong group to have those docs

@@ -916,15 +912,17 @@ public struct ThrowingTaskGroup<ChildTaskResult: Sendable, Failure: Error> {

/// Cancel all of the remaining tasks in the group.
///
/// After cancellation,
/// any new results or errors from the tasks in this group
/// are silently discarded.
Copy link
Contributor Author

@ktoso ktoso Feb 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto again wrong cancellation semantics assumption, also removed and clarified below.

///
/// Since a `TaskGroup` is a structured concurrency primitive, cancellation is
/// - when ``cancelAll()`` is invoked on it,
/// - when an error is thrown out of the `withThrowingTaskGroup(...) { }` closure,
Copy link
Contributor Author

@ktoso ktoso Feb 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throwing groups have this semantic, non throwing dont. Technically they could, but the APIs are fully non throwing today in those, including the with closure

/// - priority: The priority of the operation task.
/// Omit this parameter or pass `.unspecified`
/// to set the child task's priority to the priority of the group.
/// - operation: The operation to execute as part of the task group.
@_alwaysEmitIntoClient
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed to copy docs on this occurrence of the method

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was intentional that we didn't copy/paste the documentation onto deprecated versions.

/// to set the child task's priority to the priority of the group.
/// - operation: The operation to execute as part of the task group.
/// - Returns: `true` if the child task was added to the group;
/// otherwise `false`.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed to copy docs on this occurrence of the method

/// - Parameters:
/// - operation: The operation to execute as part of the task group.
/// - Returns: `true` if the child task was added to the group;
/// otherwise `false`.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed to copy docs on this occurrence of the method

@ktoso ktoso added the concurrency Feature: umbrella label for concurrency language features label Feb 28, 2023
@ktoso
Copy link
Contributor Author

ktoso commented Feb 28, 2023

@swift-ci please smoke test

@ktoso ktoso merged commit be4caa5 into swiftlang:main Feb 28, 2023
@ktoso ktoso deleted the wip-group-docs-fixes branch February 28, 2023 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
concurrency Feature: umbrella label for concurrency language features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants