@@ -15,18 +15,18 @@ import Swift
15
15
16
16
// ==== Task Cancellation ------------------------------------------------------
17
17
18
- /// Execute an operation with cancellation handler which will immediately be
19
- /// invoked if the current task is cancelled .
18
+ /// Execute an operation with a cancellation handler that's immediately
19
+ /// invoked if the current task is canceled .
20
20
///
21
21
/// This differs from the operation cooperatively checking for cancellation
22
22
/// and reacting to it in that the cancellation handler is _always_ and
23
- /// _immediately_ invoked when the task is cancelled . 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.
23
+ /// _immediately_ invoked when the task is canceled . For example, even if the
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.
26
26
///
27
- /// Does not check for cancellation, and always executes the passed `operation`.
27
+ /// Doesn't check for cancellation, and always executes the passed `operation`.
28
28
///
29
- /// This function returns instantly and will never suspend .
29
+ /// This function returns immediately and never suspends .
30
30
@available ( SwiftStdlib 5 . 1 , * )
31
31
public func withTaskCancellationHandler< T> (
32
32
operation: ( ) async throws -> T ,
@@ -42,7 +42,10 @@ public func withTaskCancellationHandler<T>(
42
42
43
43
@available ( SwiftStdlib 5 . 1 , * )
44
44
extension Task {
45
- /// Returns `true` if the task is cancelled, and should stop executing.
45
+ /// A Boolean value that indicates whether the task should stop executing.
46
+ ///
47
+ /// After the value of this property becomes `true`, it remains `true` indefinitely.
48
+ /// There is no way to uncancel a task.
46
49
///
47
50
/// - SeeAlso: `checkCancellation()`
48
51
@_transparent public var isCancelled : Bool {
@@ -52,10 +55,10 @@ extension Task {
52
55
53
56
@available ( SwiftStdlib 5 . 1 , * )
54
57
extension Task where Success == Never , Failure == Never {
55
- /// Returns `true` if the task is cancelled, and should stop executing.
58
+ /// A Boolean value that indicates whether the task should stop executing.
56
59
///
57
- /// If no current `Task` is available, returns `false `, as outside of a task
58
- /// context no task cancellation may be observed .
60
+ /// After the value of this property becomes `true `, it remains `true` indefinitely.
61
+ /// There is no way to uncancel a task .
59
62
///
60
63
/// - SeeAlso: `checkCancellation()`
61
64
public static var isCancelled : Bool {
@@ -67,18 +70,9 @@ extension Task where Success == Never, Failure == Never {
67
70
68
71
@available ( SwiftStdlib 5 . 1 , * )
69
72
extension Task where Success == Never , Failure == Never {
70
- /// Check if the task is cancelled and throw an `CancellationError` if it was.
71
- ///
72
- /// It is intentional that no information is passed to the task about why it
73
- /// was cancelled. A task may be cancelled for many reasons, and additional
74
- /// reasons may accrue / after the initial cancellation (for example, if the
75
- /// task fails to immediately exit, it may pass a deadline).
76
- ///
77
- /// The goal of cancellation is to allow tasks to be cancelled in a
78
- /// lightweight way, not to be a secondary method of inter-task communication.
73
+ /// Throws an error if the task was canceled.
79
74
///
80
- /// ### Suspension
81
- /// This function returns instantly and will never suspend.
75
+ /// The error is always an instance of `Task.CancellationError`.
82
76
///
83
77
/// - SeeAlso: `isCancelled()`
84
78
public static func checkCancellation( ) throws {
@@ -88,10 +82,10 @@ extension Task where Success == Never, Failure == Never {
88
82
}
89
83
}
90
84
91
- /// The default cancellation thrown when a task is cancelled .
85
+ /// An error that indicates a task was canceled .
92
86
///
93
87
/// This error is also thrown automatically by `Task.checkCancellation()`,
94
- /// if the current task has been cancelled .
88
+ /// if the current task has been canceled .
95
89
@available ( SwiftStdlib 5 . 1 , * )
96
90
public struct CancellationError : Error {
97
91
// no extra information, cancellation is intended to be light-weight
0 commit comments