@@ -15,18 +15,18 @@ import Swift
1515
1616// ==== Task Cancellation ------------------------------------------------------
1717
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 .
2020///
2121/// This differs from the operation cooperatively checking for cancellation
2222/// 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.
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 ( SwiftStdlib 5 . 1 , * )
3131public func withTaskCancellationHandler< T> (
3232 operation: ( ) async throws -> T ,
@@ -42,7 +42,10 @@ public func withTaskCancellationHandler<T>(
4242
4343@available ( SwiftStdlib 5 . 1 , * )
4444extension 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.
4649 ///
4750 /// - SeeAlso: `checkCancellation()`
4851 @_transparent public var isCancelled : Bool {
@@ -52,10 +55,10 @@ extension Task {
5255
5356@available ( SwiftStdlib 5 . 1 , * )
5457extension 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.
5659 ///
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 .
5962 ///
6063 /// - SeeAlso: `checkCancellation()`
6164 public static var isCancelled : Bool {
@@ -67,18 +70,9 @@ extension Task where Success == Never, Failure == Never {
6770
6871@available ( SwiftStdlib 5 . 1 , * )
6972extension 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.
7974 ///
80- /// ### Suspension
81- /// This function returns instantly and will never suspend.
75+ /// The error is always an instance of `Task.CancellationError`.
8276 ///
8377 /// - SeeAlso: `isCancelled()`
8478 public static func checkCancellation( ) throws {
@@ -88,10 +82,10 @@ extension Task where Success == Never, Failure == Never {
8882 }
8983}
9084
91- /// The default cancellation thrown when a task is cancelled .
85+ /// An error that indicates a task was canceled .
9286///
9387/// 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 .
9589@available ( SwiftStdlib 5 . 1 , * )
9690public struct CancellationError : Error {
9791 // no extra information, cancellation is intended to be light-weight
0 commit comments