Skip to content

Commit e755dec

Browse files
authored
Merge pull request #82894 from amartini51/fixup_pr_82558
Revise task group docs for style, fixing issues in the content changed in #82558 and some nearby content.
2 parents af7d54f + 74c3dbc commit e755dec

File tree

4 files changed

+31
-33
lines changed

4 files changed

+31
-33
lines changed

stdlib/public/Concurrency/DiscardingTaskGroup.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import Swift
2525
/// A group *always* waits for all of its child tasks
2626
/// to complete before it returns. Even canceled tasks must run until
2727
/// completion before this function returns.
28-
/// Cancelled child tasks cooperatively react to cancellation and attempt
28+
/// Canceled child tasks cooperatively react to cancellation and attempt
2929
/// to return as early as possible.
3030
/// After this function returns, the task group is always empty.
3131
///
@@ -205,7 +205,7 @@ public struct DiscardingTaskGroup {
205205
/// If you add a task to a group after canceling the group,
206206
/// that task is canceled immediately after being added to the group.
207207
///
208-
/// Immediately canceled child tasks should therefore cooperatively check for and
208+
/// Immediately canceled child tasks should therefore cooperatively check for and
209209
/// react to cancellation, e.g. by throwing an `CancellationError` at their
210210
/// earliest convenience, or otherwise handling the cancellation.
211211
///
@@ -427,7 +427,7 @@ public func _unsafeInheritExecutor_withThrowingDiscardingTaskGroup<GroupResult>(
427427
///
428428
/// - when ``cancelAll()`` is invoked on it,
429429
/// - when an error is thrown out of the `withThrowingDiscardingTaskGroup { ... }` closure,
430-
/// - when the ``Task`` running this task group is canceled .
430+
/// - when the ``Task`` running this task group is canceled.
431431
///
432432
/// But also, and uniquely in *discarding* task groups:
433433
/// - when *any* of its child tasks throws.
@@ -436,7 +436,7 @@ public func _unsafeInheritExecutor_withThrowingDiscardingTaskGroup<GroupResult>(
436436
/// whenever *any* child task throws an error is a behavior unique to discarding task groups,
437437
/// because achieving such semantics is not possible otherwise, due to the missing `next()` method
438438
/// on discarding groups. Accumulating task groups can implement this by manually polling `next()`
439-
/// and deciding to `cancelAll()` when they decide an error should cause the group to become canceled,
439+
/// and deciding to `cancelAll()` when they decide an error should cause the group to become canceled,
440440
/// however a discarding group cannot poll child tasks for results and therefore assumes that child
441441
/// task throws are an indication of a group wide failure. In order to avoid such behavior,
442442
/// use a ``DiscardingTaskGroup`` instead of a throwing one, or catch specific errors in
@@ -447,7 +447,7 @@ public func _unsafeInheritExecutor_withThrowingDiscardingTaskGroup<GroupResult>(
447447
/// tasks).
448448
///
449449
/// A canceled task group can still keep adding tasks, however they will start
450-
/// being immediately canceled, and may act accordingly to this. To avoid adding
450+
/// being immediately canceled, and may act accordingly to this. To avoid adding
451451
/// new tasks to an already canceled task group, use ``addTaskUnlessCancelled(priority:body:)``
452452
/// rather than the plain ``addTask(priority:body:)`` which adds tasks unconditionally.
453453
///

stdlib/public/Concurrency/TaskCancellation.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ import Swift
3939
/// ### Execution order and semantics
4040
/// The `operation` closure is always invoked, even when the
4141
/// `withTaskCancellationHandler(operation:onCancel:)` method is called from a task
42-
/// that was already cancelled.
42+
/// that was already canceled.
4343
///
4444
/// When `withTaskCancellationHandler(operation:onCancel:)` is used in a task that has already been
45-
/// cancelled, the cancellation handler will be executed
45+
/// canceled, the cancellation handler will be executed
4646
/// immediately before the `operation` closure gets to execute.
4747
///
48-
/// This allows the cancellation handler to set some external "cancelled" flag
48+
/// This allows the cancellation handler to set some external "canceled" flag
4949
/// that the operation may be *atomically* checking for in order to avoid
5050
/// performing any actual work once the operation gets to run.
5151
///

stdlib/public/Concurrency/TaskGroup.swift

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import Swift
1717
/// Starts a new scope that can contain a dynamic number of child tasks.
1818
///
1919
/// A group *always* waits for all of its child tasks
20-
/// to complete before it returns. Even cancelled tasks must run until
20+
/// to complete before it returns. Even canceled tasks must run until
2121
/// completion before this function returns.
22-
/// Cancelled child tasks cooperatively react to cancellation and attempt
22+
/// Canceled child tasks cooperatively react to cancellation and attempt
2323
/// to return as early as possible.
2424
/// After this function returns, the task group is always empty.
2525
///
@@ -265,29 +265,26 @@ public func _unsafeInheritExecutor_withThrowingTaskGroup<ChildTaskResult, GroupR
265265
/// Structured Concurrency
266266
/// ======================
267267
///
268+
/// Structured concurrency is a way to organize your program, and tasks, in such a way that
269+
/// tasks don't outlive the scope in which they are created. Within a structured task hierarchy,
270+
/// no child task remains running longer than its parent task. This guarantee simplifies reasoning about resource usage,
271+
/// and is a powerful mechanism that you can use to write well-behaved concurrent programs.
272+
///
268273
/// A task group is the primary way to create structured concurrency tasks in Swift.
269-
/// Another way of creating structured tasks are `async let` declarations.
274+
/// Another way of creating structured tasks is an `async let` declaration.
270275
///
271276
/// Structured concurrency tasks are often called "child tasks" because of their relationship with their parent task.
272-
/// A child task will inherit the parent's priority, task-local values, and will be structured in the sense that its
273-
/// lifetime will never exceed the lifetime of the parent task.
274-
///
275-
/// A child task inherits the parent's priority, task-local values, and will be structured in the sense that its
277+
/// A child task inherits the parent's priority, task-local values, and is structured in the sense that its
276278
/// lifetime never exceeds the lifetime of the parent task.
277279
///
278280
/// A task group *always* waits for all child tasks to complete before it's destroyed.
279281
/// Specifically, `with...TaskGroup` APIs don't return until all the child tasks
280282
/// created in the group's scope have completed running.
281283
///
282-
/// Structured concurrency is a way to organize your program, and tasks, in such a way that
283-
/// tasks don't outlive the scope in which they are created. Within a structured task hierarchy,
284-
/// no child task will remains running longer than its parent task. This simplifies reasoning about resource usage,
285-
/// and is a powerful mechanism that you can use to write well-behaved concurrent programs.
286-
///
287-
/// Structured Concurrency APIs (including task groups and `async let`), will *always* await the
284+
/// Structured concurrency APIs (including task groups and `async let`), *always* waits for the
288285
/// completion of tasks contained within their scope before returning. Specifically, this means that
289-
/// even if one were to await a single task result and return it from a `withTaskGroup` function body,
290-
/// the group will automatically await all the remaining tasks before returning:
286+
/// even if you await a single task result and return it from a `withTaskGroup` function body,
287+
/// the group automatically waits for all the remaining tasks before returning:
291288
///
292289
/// func takeFirst(actions: [@Sendable () -> Int]) async -> Int? {
293290
/// await withTaskGroup { group in
@@ -300,7 +297,7 @@ public func _unsafeInheritExecutor_withThrowingTaskGroup<ChildTaskResult, GroupR
300297
/// }
301298
///
302299
/// In the above example, even though the code returns the first collected integer from all actions added to the task group,
303-
/// the task group will *always*, automatically, waits for the completion of all the resulting tasks.
300+
/// the task group *always*, automatically, waits for the completion of all the resulting tasks.
304301
///
305302
/// You can use `group.cancelAll()` to signal cancellation to the remaining in-progress tasks,
306303
/// however this doesn't interrupt their execution automatically.
@@ -326,7 +323,7 @@ public func _unsafeInheritExecutor_withThrowingTaskGroup<ChildTaskResult, GroupR
326323
/// but other tasks are better not even being created
327324
/// when you know they can't produce useful results.
328325
///
329-
/// In non-throwing task groups the tasks you add to a group with this method are nonthrowing,
326+
/// In nonthrowing task groups the tasks you add to a group with this method are nonthrowing,
330327
/// those tasks can't respond to cancellation by throwing `CancellationError`.
331328
/// The tasks must handle cancellation in some other way,
332329
/// such as returning the work completed so far, returning an empty result, or returning `nil`.
@@ -339,17 +336,18 @@ public func _unsafeInheritExecutor_withThrowingTaskGroup<ChildTaskResult, GroupR
339336
/// any order.
340337
///
341338
/// ### Cancellation behavior
339+
///
342340
/// A task group becomes canceled in one of the following ways:
343341
///
344-
/// - when ``cancelAll()`` is invoked on it,
345-
/// - when the ``Task`` running this task group is cancelled.
342+
/// - When ``cancelAll()`` is invoked on it.
343+
/// - When the ``Task`` running this task group is canceled.
346344
///
347-
/// Since a `TaskGroup` is a structured concurrency primitive, cancellation is
345+
/// Because a `TaskGroup` is a structured concurrency primitive, cancellation is
348346
/// automatically propagated through all of its child-tasks (and their child
349347
/// tasks).
350348
///
351349
/// A canceled task group can still keep adding tasks, however they will start
352-
/// being immediately cancelled, and may act accordingly to this. To avoid adding
350+
/// being immediately canceled, and might respond accordingly. To avoid adding
353351
/// new tasks to an already canceled task group, use ``addTaskUnlessCancelled(name:priority:body:)``
354352
/// rather than the plain ``addTask(name:priority:body:)`` which adds tasks unconditionally.
355353
///
@@ -551,14 +549,14 @@ extension TaskGroup: Sendable { }
551549
///
552550
/// - when ``cancelAll()`` is invoked on it,
553551
/// - when an error is thrown out of the `withThrowingTaskGroup(...) { }` closure,
554-
/// - when the ``Task`` running this task group is cancelled.
552+
/// - when the ``Task`` running this task group is canceled.
555553
///
556554
/// Since a `ThrowingTaskGroup` is a structured concurrency primitive, cancellation is
557555
/// automatically propagated through all of its child-tasks (and their child
558556
/// tasks).
559557
///
560558
/// A canceled task group can still keep adding tasks, however they will start
561-
/// being immediately cancelled, and may act accordingly to this. To avoid adding
559+
/// being immediately canceled, and may act accordingly to this. To avoid adding
562560
/// new tasks to an already canceled task group, use ``addTaskUnlessCancelled(priority:body:)``
563561
/// rather than the plain ``addTask(priority:body:)`` which adds tasks unconditionally.
564562
///
@@ -616,7 +614,7 @@ public struct ThrowingTaskGroup<ChildTaskResult: Sendable, Failure: Error> {
616614
/// Wait for all of the group's remaining tasks to complete.
617615
///
618616
/// If any of the tasks throw, the *first* error thrown is captured
619-
/// and re-thrown by this method although the task group is *not* cancelled
617+
/// and re-thrown by this method although the task group is *not* canceled
620618
/// when this happens.
621619
///
622620
/// ### Cancelling the task group on first error

stdlib/public/Concurrency/TaskSleepDuration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ extension Task where Success == Never, Failure == Never {
209209

210210
/// Suspends the current task for the given duration.
211211
///
212-
/// If the task is cancelled before the time ends, this function throws
212+
/// If the task is canceled before the time ends, this function throws
213213
/// `CancellationError`.
214214
///
215215
/// This function doesn't block the underlying thread.

0 commit comments

Comments
 (0)