@@ -23,14 +23,13 @@ import Swift
23
23
/// by invoking the appropriate context-sensitive static functions which operate
24
24
/// on the current task.
25
25
///
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
28
28
/// completion of the task.
29
29
///
30
30
/// These partial periods towards the task's completion are `PartialAsyncTask`.
31
31
/// Unless you're implementing a scheduler,
32
32
/// you don't generally interact with partial tasks directly.
33
- /// ◊TODO: partial tasks might get replaced with jobs (see PR 36878)
34
33
///
35
34
/// Task Cancellation
36
35
/// =================
@@ -41,10 +40,10 @@ import Swift
41
40
/// the correct way to stop that work varies.
42
41
/// Likewise,
43
42
/// 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 .
48
47
/// If you only need to throw an error to stop the work,
49
48
/// call the `Task.checkCancellation()` function to check for cancellation.
50
49
/// Other responses to cancellation include
@@ -70,14 +69,14 @@ public struct Task {
70
69
@available ( macOS 9999 , iOS 9999 , watchOS 9999 , tvOS 9999 , * )
71
70
extension Task {
72
71
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.
75
74
///
76
75
/// 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.
78
77
/// In a synchronous context,
79
78
/// this property's value depends on whether the synchronous operation was
80
- /// itself called from an asynchronous context.
79
+ /// called from an asynchronous context.
81
80
/// For example:
82
81
///
83
82
/// func hello() {
@@ -116,8 +115,9 @@ extension Task {
116
115
///
117
116
/// If you access this property outside of any task,
118
117
/// 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`.
121
121
///
122
122
/// - SeeAlso: `Task.priority`
123
123
public static var currentPriority : Priority {
@@ -142,11 +142,11 @@ extension Task {
142
142
143
143
/// The priority of a task.
144
144
///
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.
146
146
/// The behavior varies depending on the executor currently being used.
147
147
/// Typically, executors attempt to run tasks with a higher priority
148
148
/// 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
150
150
/// platform and `Executor` implementation.
151
151
///
152
152
/// Child tasks automatically inherit their parent task's priority.
@@ -158,15 +158,15 @@ extension Task {
158
158
/// that is, the task is treated as it if had a higher priority,
159
159
/// without actually changing the priority of the task:
160
160
///
161
- /// - If a task running on behalf of an actor,
161
+ /// - If a task runs on behalf of an actor,
162
162
/// and a new higher-priority task is enqueued to the actor,
163
163
/// then the actor's current task is temporarily elevated
164
164
/// to the priority of the enqueued task.
165
165
/// This priority elevation allows the new task
166
166
/// to be processed at (effectively) the priority it was enqueued with.
167
167
/// - If a task is created with a `Task.Handle`
168
168
/// 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.
170
170
///
171
171
/// In both cases, priority elevation helps you prevent a low-priority task
172
172
/// blocking the execution of a high priority task,
@@ -209,8 +209,8 @@ extension Task {
209
209
///
210
210
/// You can use a task's handle to wait for its result or cancel the task.
211
211
///
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.
214
214
/// However, if you discard a task's handle, you give up the ability
215
215
/// to wait for that task's result or cancel the task.
216
216
public struct Handle < Success, Failure: Error > : Sendable {
@@ -228,9 +228,9 @@ extension Task {
228
228
229
229
/// Wait for the task to complete, returning its result or throw an error.
230
230
///
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.
234
234
///
235
235
/// If the task throws an error, this method propogates that error.
236
236
/// Tasks that respond to cancellation by throwing `Task.CancellationError`
@@ -243,15 +243,15 @@ extension Task {
243
243
244
244
/// Wait for the task to complete, returning its result or its error.
245
245
///
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.
249
249
///
250
250
/// If the task throws an error, this method propogates that error.
251
251
/// Tasks that respond to cancellation by throwing `Task.CancellationError`
252
252
/// have that error propogated here upon cancellation.
253
253
///
254
- /// - Returns: If the task suceeded , `.success`
254
+ /// - Returns: If the task succeeded , `.success`
255
255
/// with the task's result as the associated value;
256
256
/// otherwise, `.failure` with the error as the associated value.
257
257
public func getResult( ) async -> Result < Success , Failure > {
@@ -267,9 +267,9 @@ extension Task {
267
267
/// Whether this function has any effect is task-dependent.
268
268
///
269
269
/// 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.
273
273
public func cancel( ) {
274
274
Builtin . cancelAsyncTask ( _task)
275
275
}
@@ -279,17 +279,18 @@ extension Task {
279
279
@available ( macOS 9999 , iOS 9999 , watchOS 9999 , tvOS 9999 , * )
280
280
extension Task . Handle where Failure == Never {
281
281
282
- /// Wait for the task to complete, returning its result.
282
+ /// Wait for the task to complete and return its result.
283
283
///
284
284
/// 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.
288
289
///
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 .
293
294
public func get( ) async -> Success {
294
295
return await _taskFutureGet ( _task)
295
296
}
@@ -449,7 +450,7 @@ extension Task {
449
450
/// Runs the given nonthrowing operation asynchronously
450
451
/// as part of a new top-level task.
451
452
///
452
- /// Avoid using a detached task unless it isn't possible
453
+ /// Don't use a detached task unless it isn't possible
453
454
/// to model the operation using structured concurrency features like child tasks.
454
455
/// Child tasks inherit the parent task's priority and task-local storage,
455
456
/// and canceling a parent task automatically cancels all of its child tasks.
@@ -462,7 +463,6 @@ extension Task {
462
463
///
463
464
/// - Parameters:
464
465
/// - priority: The priority of the task.
465
- /// - executor: The executor that the detached closure should start executing on.
466
466
/// - operation: The operation to perform.
467
467
///
468
468
/// - Returns: A handle to the task.
@@ -505,7 +505,6 @@ public func detach<T>(
505
505
///
506
506
/// - Parameters:
507
507
/// - priority: The priority of the task.
508
- /// - executor: The executor that the detached closure should start executing on.
509
508
/// - operation: The operation to perform.
510
509
///
511
510
/// - Returns: A handle to the task.
@@ -546,7 +545,6 @@ public func detach<T>(
546
545
///
547
546
/// - Parameters:
548
547
/// - priority: The priority of the task.
549
- /// - executor: The executor that the detached closure should start executing on.
550
548
/// - operation: The operation to perform.
551
549
///
552
550
/// - Returns: A handle to the task.
@@ -564,7 +562,7 @@ public func asyncDetached<T>(
564
562
///
565
563
/// If the operation throws an error, this method propogates that error.
566
564
///
567
- /// Avoid using a detached task unless it isn't possible
565
+ /// Don't use a detached task unless it isn't possible
568
566
/// to model the operation using structured concurrency features like child tasks.
569
567
/// Child tasks inherit the parent task's priority and task-local storage,
570
568
/// and canceling a parent task automatically cancels all of its child tasks.
@@ -577,7 +575,6 @@ public func asyncDetached<T>(
577
575
///
578
576
/// - Parameters:
579
577
/// - priority: The priority of the task.
580
- /// - executor: The executor that the detached closure should start executing on.
581
578
/// - operation: The operation to perform.
582
579
///
583
580
/// - Returns: A handle to the task.
@@ -600,7 +597,7 @@ public func asyncDetached<T>(
600
597
/// Like `detach(priority:operation:)`,
601
598
/// this function creates a separate, top-level task.
602
599
/// Unlike `detach(priority:operation:)`,
603
- /// the task creating by `async(priority:operation:)`
600
+ /// the task created by `async(priority:operation:)`
604
601
/// inherits the priority and actor context of the caller,
605
602
/// so the operation is treated more like an asynchronous extension
606
603
/// to the synchronous operation.
@@ -634,7 +631,7 @@ func async(
634
631
/// Like `detach(priority:operation:)`,
635
632
/// this function creates a separate, top-level task.
636
633
/// Unlike `detach(priority:operation:)`,
637
- /// the task creating by `async(priority:operation:)`
634
+ /// the task created by `async(priority:operation:)`
638
635
/// inherits the priority and actor context of the caller,
639
636
/// so the operation is treated more like an asynchronous extension
640
637
/// to the synchronous operation.
@@ -675,7 +672,7 @@ public func async<T>(
675
672
/// Like `detach(priority:operation:)`,
676
673
/// this function creates a separate, top-level task.
677
674
/// Unlike `detach(priority:operation:)`,
678
- /// the task creating by `async(priority:operation:)`
675
+ /// the task created by `async(priority:operation:)`
679
676
/// inherits the priority and actor context of the caller,
680
677
/// so the operation is treated more like an asynchronous extension
681
678
/// to the synchronous operation.
@@ -723,13 +720,13 @@ func _runAsyncHandler(operation: @escaping () async -> ()) {
723
720
724
721
@available ( macOS 9999 , iOS 9999 , watchOS 9999 , tvOS 9999 , * )
725
722
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.
728
725
///
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.
730
727
/// Depending on a variety of factors,
731
728
/// it could be suspended for exactly the given duration,
732
- /// or for a much longer duration.
729
+ /// or for a longer duration.
733
730
///
734
731
/// Calling this method doesn't block the underlying thread.
735
732
///
@@ -765,7 +762,7 @@ extension Task {
765
762
/// to let other tasks run for a while
766
763
/// before execution returns back to this task.
767
764
///
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,
769
766
/// the executor immediately resumes execution of the same task.
770
767
/// As such,
771
768
/// this method isn't necessarily a way to avoid resource starvation.
@@ -810,15 +807,15 @@ extension Task {
810
807
/// Calls a closure with an unsafe handle to current task.
811
808
///
812
809
/// 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
814
811
/// because an asynchronous function always runs in the context of a task.
815
812
/// However if you call this function from the body of a synchronous function,
816
813
/// and that function isn't executing in the context of any task,
817
814
/// the unsafe task handle is `nil`.
818
815
///
819
816
/// Don't try to store an unsafe task handle
820
817
/// 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 ,
822
819
/// and the behavior of accessing an unsafe task handle
823
820
/// outside of the `withUnsafeCurrentTask(body:)` method's closure isn't defined.
824
821
/// Instead, use the `task` property of `UnsafeCurrentTask`
@@ -852,7 +849,7 @@ public func withUnsafeCurrentTask<T>(body: (UnsafeCurrentTask?) throws -> T) ret
852
849
/// call the `withUnsafeCurrentTask(body:)` method.
853
850
/// Don't try to store an unsafe task handle
854
851
/// 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 ,
856
853
/// and the behavior of accessing an unsafe task handle
857
854
/// outside of the `withUnsafeCurrentTask(body:)` method's closure isn't defined.
858
855
/// Instead, use the `task` property of `UnsafeCurrentTask`
@@ -886,8 +883,8 @@ public struct UnsafeCurrentTask {
886
883
887
884
/// A Boolean value that indicates whether the current task was canceled.
888
885
///
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.
891
888
///
892
889
/// - SeeAlso: `checkCancellation()`
893
890
public var isCancelled : Bool {
0 commit comments