@@ -17,9 +17,9 @@ import Swift
17
17
/// Starts a new scope that can contain a dynamic number of child tasks.
18
18
///
19
19
/// 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
21
21
/// 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
23
23
/// to return as early as possible.
24
24
/// After this function returns, the task group is always empty.
25
25
///
@@ -265,29 +265,26 @@ public func _unsafeInheritExecutor_withThrowingTaskGroup<ChildTaskResult, GroupR
265
265
/// Structured Concurrency
266
266
/// ======================
267
267
///
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
+ ///
268
273
/// 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 .
270
275
///
271
276
/// 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
276
278
/// lifetime never exceeds the lifetime of the parent task.
277
279
///
278
280
/// A task group *always* waits for all child tasks to complete before it's destroyed.
279
281
/// Specifically, `with...TaskGroup` APIs don't return until all the child tasks
280
282
/// created in the group's scope have completed running.
281
283
///
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
288
285
/// 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:
291
288
///
292
289
/// func takeFirst(actions: [@Sendable () -> Int]) async -> Int? {
293
290
/// await withTaskGroup { group in
@@ -300,7 +297,7 @@ public func _unsafeInheritExecutor_withThrowingTaskGroup<ChildTaskResult, GroupR
300
297
/// }
301
298
///
302
299
/// 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.
304
301
///
305
302
/// You can use `group.cancelAll()` to signal cancellation to the remaining in-progress tasks,
306
303
/// however this doesn't interrupt their execution automatically.
@@ -326,7 +323,7 @@ public func _unsafeInheritExecutor_withThrowingTaskGroup<ChildTaskResult, GroupR
326
323
/// but other tasks are better not even being created
327
324
/// when you know they can't produce useful results.
328
325
///
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,
330
327
/// those tasks can't respond to cancellation by throwing `CancellationError`.
331
328
/// The tasks must handle cancellation in some other way,
332
329
/// 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
339
336
/// any order.
340
337
///
341
338
/// ### Cancellation behavior
339
+ ///
342
340
/// A task group becomes canceled in one of the following ways:
343
341
///
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 .
346
344
///
347
- /// Since a `TaskGroup` is a structured concurrency primitive, cancellation is
345
+ /// Because a `TaskGroup` is a structured concurrency primitive, cancellation is
348
346
/// automatically propagated through all of its child-tasks (and their child
349
347
/// tasks).
350
348
///
351
349
/// 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
353
351
/// new tasks to an already canceled task group, use ``addTaskUnlessCancelled(name:priority:body:)``
354
352
/// rather than the plain ``addTask(name:priority:body:)`` which adds tasks unconditionally.
355
353
///
@@ -551,14 +549,14 @@ extension TaskGroup: Sendable { }
551
549
///
552
550
/// - when ``cancelAll()`` is invoked on it,
553
551
/// - 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 .
555
553
///
556
554
/// Since a `ThrowingTaskGroup` is a structured concurrency primitive, cancellation is
557
555
/// automatically propagated through all of its child-tasks (and their child
558
556
/// tasks).
559
557
///
560
558
/// 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
562
560
/// new tasks to an already canceled task group, use ``addTaskUnlessCancelled(priority:body:)``
563
561
/// rather than the plain ``addTask(priority:body:)`` which adds tasks unconditionally.
564
562
///
@@ -616,7 +614,7 @@ public struct ThrowingTaskGroup<ChildTaskResult: Sendable, Failure: Error> {
616
614
/// Wait for all of the group's remaining tasks to complete.
617
615
///
618
616
/// 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
620
618
/// when this happens.
621
619
///
622
620
/// ### Cancelling the task group on first error
0 commit comments