Skip to content

Commit 112acee

Browse files
committed
Incorporate editorial feedback.
For rdar://77330408
1 parent 614c008 commit 112acee

File tree

4 files changed

+98
-98
lines changed

4 files changed

+98
-98
lines changed

stdlib/public/Concurrency/PartialAsyncTask.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import Swift
1414
@_implementationOnly import _SwiftConcurrencyShims
1515

1616
/// A partial task is a unit of scheduleable work.
17+
///
18+
/// Unless you're implementing a scheduler,
19+
/// you don't generally interact with partial tasks directly.
1720
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
1821
@frozen
1922
public struct PartialAsyncTask {

stdlib/public/Concurrency/Task.swift

Lines changed: 53 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ import Swift
2323
/// by invoking the appropriate context-sensitive static functions which operate
2424
/// on the current task.
2525
///
26-
/// A task's execution can be seen as a series of periods where the task was
27-
/// running. Each such period ends at a suspension point or the
26+
/// A task's execution can be seen as a series of periods where the task ran.
27+
/// Each such period ends at a suspension point or the
2828
/// completion of the task.
2929
///
3030
/// These partial periods towards the task's completion are `PartialAsyncTask`.
3131
/// Unless you're implementing a scheduler,
3232
/// you don't generally interact with partial tasks directly.
33-
/// ◊TODO: partial tasks might get replaced with jobs (see PR 36878)
3433
///
3534
/// Task Cancellation
3635
/// =================
@@ -41,10 +40,10 @@ import Swift
4140
/// the correct way to stop that work varies.
4241
/// Likewise,
4342
/// it's the responsibility of the code running as part of the task
44-
/// to check for cancellation at the appropriate points when stopping is possible.
45-
/// In a long-running task, you might need to check for cancellation repeatedly,
46-
/// and cancellation at different times
47-
/// might require stopping different aspects of that work.
43+
/// to check for cancellation whenever stopping is appropriate.
44+
/// In a long-task that includes multiple pieces,
45+
/// you might need to check for cancellation at several points,
46+
/// and handle cancellation differently at each point.
4847
/// If you only need to throw an error to stop the work,
4948
/// call the `Task.checkCancellation()` function to check for cancellation.
5049
/// Other responses to cancellation include
@@ -70,14 +69,14 @@ public struct Task {
7069
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
7170
extension Task {
7271

73-
/// Returns the task that this code is being run on,
74-
/// or `nil` if this property is accessed outside of any task.
72+
/// Returns the task that this code runs on,
73+
/// or `nil` when you access this property outside of any task.
7574
///
7675
/// If you read this property from the context of an asynchronous function or closure,
77-
/// the current task is guaranteed to be non-nil.
76+
/// the current task is non-nil.
7877
/// In a synchronous context,
7978
/// this property's value depends on whether the synchronous operation was
80-
/// itself called from an asynchronous context.
79+
/// called from an asynchronous context.
8180
/// For example:
8281
///
8382
/// func hello() {
@@ -116,8 +115,9 @@ extension Task {
116115
///
117116
/// If you access this property outside of any task,
118117
/// this queries the system to determine the
119-
/// priority at which the current function is running. If the system cannot
120-
/// provide an appropriate priority, returns `Priority.default`.
118+
/// priority at which the current function is running.
119+
/// If the system can't provide a priority,
120+
/// this property's value is `Priority.default`.
121121
///
122122
/// - SeeAlso: `Task.priority`
123123
public static var currentPriority: Priority {
@@ -142,11 +142,11 @@ extension Task {
142142

143143
/// The priority of a task.
144144
///
145-
/// The executor determines how priority information impacts the way tasks are scheduled.
145+
/// The executor determines how priority information affects the way tasks are scheduled.
146146
/// The behavior varies depending on the executor currently being used.
147147
/// Typically, executors attempt to run tasks with a higher priority
148148
/// before tasks with a lower priority.
149-
/// However, the exact semantics of how priority is treated are left up to each
149+
/// However, the semantics of how priority is treated are left up to each
150150
/// platform and `Executor` implementation.
151151
///
152152
/// Child tasks automatically inherit their parent task's priority.
@@ -158,15 +158,15 @@ extension Task {
158158
/// that is, the task is treated as it if had a higher priority,
159159
/// without actually changing the priority of the task:
160160
///
161-
/// - If a task running on behalf of an actor,
161+
/// - If a task runs on behalf of an actor,
162162
/// and a new higher-priority task is enqueued to the actor,
163163
/// then the actor's current task is temporarily elevated
164164
/// to the priority of the enqueued task.
165165
/// This priority elevation allows the new task
166166
/// to be processed at (effectively) the priority it was enqueued with.
167167
/// - If a task is created with a `Task.Handle`
168168
/// and a higher-priority task calls the `await handle.get()` method,
169-
/// then the priority of this task is increased until the task completes.
169+
/// then the priority of this task increases until the task completes.
170170
///
171171
/// In both cases, priority elevation helps you prevent a low-priority task
172172
/// blocking the execution of a high priority task,
@@ -209,8 +209,8 @@ extension Task {
209209
///
210210
/// You can use a task's handle to wait for its result or cancel the task.
211211
///
212-
/// It's not a programming error to discard a task's handle without awaiting or canceling the task.
213-
/// A task runs whether or not you still have its handle stored somewhere.
212+
/// It isn't a programming error to discard a task's handle without awaiting or canceling the task.
213+
/// A task runs regardless of whether you still have its handle stored somewhere.
214214
/// However, if you discard a task's handle, you give up the ability
215215
/// to wait for that task's result or cancel the task.
216216
public struct Handle<Success, Failure: Error>: Sendable {
@@ -228,9 +228,9 @@ extension Task {
228228

229229
/// Wait for the task to complete, returning its result or throw an error.
230230
///
231-
/// If the task hasn't completed yet, its priority is elevated to the
232-
/// priority of the current task. Note that this may not be as effective as
233-
/// creating the task with the right priority to in the first place.
231+
/// If the task hasn't completed, its priority increases to the
232+
/// priority of the current task. Note that this isn't as effective as
233+
/// creating the task with the correct priority.
234234
///
235235
/// If the task throws an error, this method propogates that error.
236236
/// Tasks that respond to cancellation by throwing `Task.CancellationError`
@@ -243,15 +243,15 @@ extension Task {
243243

244244
/// Wait for the task to complete, returning its result or its error.
245245
///
246-
/// If the task hasn't completed yet, its priority is elevated to the
247-
/// priority of the current task. Note that this may not be as effective as
248-
/// creating the task with the right priority to in the first place.
246+
/// If the task hasn't completed, its priority increases to the
247+
/// priority of the current task. Note that this isn't as effective as
248+
/// creating the task with the correct priority.
249249
///
250250
/// If the task throws an error, this method propogates that error.
251251
/// Tasks that respond to cancellation by throwing `Task.CancellationError`
252252
/// have that error propogated here upon cancellation.
253253
///
254-
/// - Returns: If the task suceeded, `.success`
254+
/// - Returns: If the task succeeded, `.success`
255255
/// with the task's result as the associated value;
256256
/// otherwise, `.failure` with the error as the associated value.
257257
public func getResult() async -> Result<Success, Failure> {
@@ -267,9 +267,9 @@ extension Task {
267267
/// Whether this function has any effect is task-dependent.
268268
///
269269
/// For a task to respect cancellation it must cooperatively check for it
270-
/// while running. Many tasks will check for cancellation before beginning
271-
/// their "actual work", however this is not a requirement nor is it guaranteed
272-
/// how and when tasks check for cancellation in general.
270+
/// while running. Many tasks check for cancellation before beginning
271+
/// their "actual work"; however, this isn't a requirement nor is it guaranteed
272+
/// how and when tasks check for cancellation.
273273
public func cancel() {
274274
Builtin.cancelAsyncTask(_task)
275275
}
@@ -279,17 +279,18 @@ extension Task {
279279
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
280280
extension Task.Handle where Failure == Never {
281281

282-
/// Wait for the task to complete, returning its result.
282+
/// Wait for the task to complete and return its result.
283283
///
284284
/// If the task hasn't completed,
285-
/// its priority is elevated to the priority of the current task.
286-
/// Note that this may not be as effective as
287-
/// creating the task with the right priority in the first place.
285+
/// its priority increases to that of the current task.
286+
/// Note that this might not be as effective as
287+
/// creating the task with the correct priority,
288+
/// depending on the executor's scheduling details.
288289
///
289-
/// The task that this handle refers to might check for cancellation ---
290-
/// however, since this method is nonthrowing,
291-
/// the task can't throw `CancellationError` and needs to use another method
292-
/// like returning `nil` instead.
290+
/// The task that this handle refers to might check for cancellation.
291+
/// However, because this method is nonthrowing,
292+
/// the task needs to handle cancellation using an approach like returning `nil`
293+
/// instead of throwing an error.
293294
public func get() async -> Success {
294295
return await _taskFutureGet(_task)
295296
}
@@ -449,7 +450,7 @@ extension Task {
449450
/// Runs the given nonthrowing operation asynchronously
450451
/// as part of a new top-level task.
451452
///
452-
/// Avoid using a detached task unless it isn't possible
453+
/// Don't use a detached task unless it isn't possible
453454
/// to model the operation using structured concurrency features like child tasks.
454455
/// Child tasks inherit the parent task's priority and task-local storage,
455456
/// and canceling a parent task automatically cancels all of its child tasks.
@@ -462,7 +463,6 @@ extension Task {
462463
///
463464
/// - Parameters:
464465
/// - priority: The priority of the task.
465-
/// - executor: The executor that the detached closure should start executing on.
466466
/// - operation: The operation to perform.
467467
///
468468
/// - Returns: A handle to the task.
@@ -505,7 +505,6 @@ public func detach<T>(
505505
///
506506
/// - Parameters:
507507
/// - priority: The priority of the task.
508-
/// - executor: The executor that the detached closure should start executing on.
509508
/// - operation: The operation to perform.
510509
///
511510
/// - Returns: A handle to the task.
@@ -546,7 +545,6 @@ public func detach<T>(
546545
///
547546
/// - Parameters:
548547
/// - priority: The priority of the task.
549-
/// - executor: The executor that the detached closure should start executing on.
550548
/// - operation: The operation to perform.
551549
///
552550
/// - Returns: A handle to the task.
@@ -564,7 +562,7 @@ public func asyncDetached<T>(
564562
///
565563
/// If the operation throws an error, this method propogates that error.
566564
///
567-
/// Avoid using a detached task unless it isn't possible
565+
/// Don't use a detached task unless it isn't possible
568566
/// to model the operation using structured concurrency features like child tasks.
569567
/// Child tasks inherit the parent task's priority and task-local storage,
570568
/// and canceling a parent task automatically cancels all of its child tasks.
@@ -577,7 +575,6 @@ public func asyncDetached<T>(
577575
///
578576
/// - Parameters:
579577
/// - priority: The priority of the task.
580-
/// - executor: The executor that the detached closure should start executing on.
581578
/// - operation: The operation to perform.
582579
///
583580
/// - Returns: A handle to the task.
@@ -600,7 +597,7 @@ public func asyncDetached<T>(
600597
/// Like `detach(priority:operation:)`,
601598
/// this function creates a separate, top-level task.
602599
/// Unlike `detach(priority:operation:)`,
603-
/// the task creating by `async(priority:operation:)`
600+
/// the task created by `async(priority:operation:)`
604601
/// inherits the priority and actor context of the caller,
605602
/// so the operation is treated more like an asynchronous extension
606603
/// to the synchronous operation.
@@ -634,7 +631,7 @@ func async(
634631
/// Like `detach(priority:operation:)`,
635632
/// this function creates a separate, top-level task.
636633
/// Unlike `detach(priority:operation:)`,
637-
/// the task creating by `async(priority:operation:)`
634+
/// the task created by `async(priority:operation:)`
638635
/// inherits the priority and actor context of the caller,
639636
/// so the operation is treated more like an asynchronous extension
640637
/// to the synchronous operation.
@@ -675,7 +672,7 @@ public func async<T>(
675672
/// Like `detach(priority:operation:)`,
676673
/// this function creates a separate, top-level task.
677674
/// Unlike `detach(priority:operation:)`,
678-
/// the task creating by `async(priority:operation:)`
675+
/// the task created by `async(priority:operation:)`
679676
/// inherits the priority and actor context of the caller,
680677
/// so the operation is treated more like an asynchronous extension
681678
/// to the synchronous operation.
@@ -723,13 +720,13 @@ func _runAsyncHandler(operation: @escaping () async -> ()) {
723720

724721
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
725722
extension Task {
726-
/// Suspends the current task,
727-
/// and waits for at least the given duration before resuming it.
723+
/// Suspends the current task
724+
/// and waits for at least the given duration before resuming.
728725
///
729-
/// This method doesn't make guarantee how long the task is suspended.
726+
/// This method doesn't guarantee how long the task is suspended.
730727
/// Depending on a variety of factors,
731728
/// it could be suspended for exactly the given duration,
732-
/// or for a much longer duration.
729+
/// or for a longer duration.
733730
///
734731
/// Calling this method doesn't block the underlying thread.
735732
///
@@ -765,7 +762,7 @@ extension Task {
765762
/// to let other tasks run for a while
766763
/// before execution returns back to this task.
767764
///
768-
/// Note that if this task is the highest-priority task in the system,
765+
/// If this task is the highest-priority task in the system,
769766
/// the executor immediately resumes execution of the same task.
770767
/// As such,
771768
/// this method isn't necessarily a way to avoid resource starvation.
@@ -810,15 +807,15 @@ extension Task {
810807
/// Calls a closure with an unsafe handle to current task.
811808
///
812809
/// If you call this function from the body of an asynchronous function,
813-
/// the unsafe task handle passed to the closure is always be non-nil
810+
/// the unsafe task handle passed to the closure is always non-nil
814811
/// because an asynchronous function always runs in the context of a task.
815812
/// However if you call this function from the body of a synchronous function,
816813
/// and that function isn't executing in the context of any task,
817814
/// the unsafe task handle is `nil`.
818815
///
819816
/// Don't try to store an unsafe task handle
820817
/// for use outside this method's closure.
821-
/// Storing an unsafe task handle has no impact on the task's actual lifecycle,
818+
/// Storing an unsafe task handle doesn't have an impact on the task's actual life cycle,
822819
/// and the behavior of accessing an unsafe task handle
823820
/// outside of the `withUnsafeCurrentTask(body:)` method's closure isn't defined.
824821
/// Instead, use the `task` property of `UnsafeCurrentTask`
@@ -852,7 +849,7 @@ public func withUnsafeCurrentTask<T>(body: (UnsafeCurrentTask?) throws -> T) ret
852849
/// call the `withUnsafeCurrentTask(body:)` method.
853850
/// Don't try to store an unsafe task handle
854851
/// for use outside that method's closure.
855-
/// Storing an unsafe task handle has no impact on the task's actual lifecycle,
852+
/// Storing an unsafe task handle doesn't have an impact on the task's actual life cycle,
856853
/// and the behavior of accessing an unsafe task handle
857854
/// outside of the `withUnsafeCurrentTask(body:)` method's closure isn't defined.
858855
/// Instead, use the `task` property of `UnsafeCurrentTask`
@@ -886,8 +883,8 @@ public struct UnsafeCurrentTask {
886883

887884
/// A Boolean value that indicates whether the current task was canceled.
888885
///
889-
/// After the value of this property is true, it will remain true indefinitely.
890-
/// There is no uncancellation operation.
886+
/// After the value of this property is `true`, it remains `true` indefinitely.
887+
/// There is no way to uncancel the operation.
891888
///
892889
/// - SeeAlso: `checkCancellation()`
893890
public var isCancelled: Bool {

stdlib/public/Concurrency/TaskCancellation.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ import Swift
1515

1616
// ==== Task Cancellation ------------------------------------------------------
1717

18-
/// Execute an operation with cancellation handler which will immediately be
18+
/// Execute an operation with a cancellation handler that's immediately
1919
/// invoked if the current task is canceled.
2020
///
2121
/// This differs from the operation cooperatively checking for cancellation
2222
/// and reacting to it in that the cancellation handler is _always_ and
2323
/// _immediately_ invoked when the task is canceled. For example, even if the
24-
/// operation is running code which never checks for cancellation, a cancellation
25-
/// handler still would run and give us a chance to run some cleanup code.
24+
/// operation is running code that never checks for cancellation, a cancellation
25+
/// handler still runs and provides a chance to run some cleanup code.
2626
///
27-
/// Does not check for cancellation, and always executes the passed `operation`.
27+
/// Doesn't check for cancellation, and always executes the passed `operation`.
2828
///
29-
/// This function returns instantly and will never suspend.
29+
/// This function returns immediately and never suspends.
3030
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
3131
public func withTaskCancellationHandler<T>(
3232
handler: @Sendable () -> (),
@@ -88,11 +88,11 @@ extension Task {
8888
try await withTaskCancellationHandler(handler: handler, operation: operation)
8989
}
9090

91-
/// The default error thrown by a cancelled task.
91+
/// The default error thrown by a canceled task.
9292
///
9393
/// The `Task.checkCancellation()` method throws this error
9494
/// if the current task has been canceled.
95-
/// You can throw this error in your own cancellation-checking code,
95+
/// You can throw this error in your cancellation-checking code,
9696
/// or another more specific error if needed.
9797
public struct CancellationError: Error {
9898
// no extra information, cancellation is intended to be light-weight

0 commit comments

Comments
 (0)