You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: stdlib/public/Concurrency/Task.swift
+27-23Lines changed: 27 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -22,30 +22,29 @@ import Swift
22
22
/// Tasks can start running immediately after creation;
23
23
/// you don't explicitly start or schedule them.
24
24
/// After creating a task, you use the instance to interact with it ---
25
-
/// for example, to wait for it to complete or to cancel.
25
+
/// for example, to wait for it to complete or to cancel it.
26
26
/// It's not a programming error to discard a reference to a task
27
27
/// without waiting for that task to finish or canceling it.
28
-
/// A task runs regardless of whether<!-- EDIT: Don't use "whether or not". --> you keep a reference to it.
28
+
/// A task runs regardless of whether you keep a reference to it.
29
29
/// However, if you discard the reference to a task,
30
30
/// you give up the ability
31
-
/// to wait for that task's result or if it's canceled.
31
+
/// to wait for that task's result or cancel the task.
32
32
///
33
33
/// To support operations on the current task,
34
34
/// which can be either a detached task or child task,
35
35
/// `Task` also exposes class methods like `yield()`.
36
36
/// Because these methods are asynchronous,
37
37
/// they're always invoked as part of an existing task.
38
38
///
39
-
/// Only code that's running as part of the task can interact with that task
40
-
/// by invoking the appropriate context-sensitive static functions which operate
41
-
/// on the current task.<!-- FIXME: Long sentence that could probably be split in two. -->
39
+
/// Only code that's running as part of the task can interact with that task.
40
+
/// To interact with the current task,
41
+
/// you call one of the static methods on `Task`.
42
42
///
43
43
/// A task's execution can be seen as a series of periods where the task ran.
44
44
/// Each such period ends at a suspension point or the
45
45
/// completion of the task.
46
-
///
47
-
/// These partial periods towards<!-- FIXME: The preceding wording is a little awkward; please rewrite. --> the task's completion are `PartialAsyncTask`.
48
-
/// Unless you're implementing a scheduler,
46
+
/// These periods of execution are represented by instances of `PartialAsyncTask`.
47
+
/// Unless you're implementing a custom executor,
49
48
/// you don't directly interact with partial tasks.
50
49
///
51
50
/// For information about the language-level concurrency model that `Task` is part of,
/// Execute an operation with a cancellation handler that's immediately
19
-
/// invoked if the current task is canceled<!-- FIXME: Passive; rewrite. -->.
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 canceled<!-- FIXME: Passive; rewrite. -->. For example, even if the
23
+
/// _immediately_ invoked when the task is canceled. For example, even if the
24
24
/// operation is running code that never checks for cancellation, a cancellation
25
25
/// handler still runs and provides a chance to run some cleanup code.
26
26
///
@@ -44,7 +44,10 @@ public func withTaskCancellationHandler<T>(
44
44
45
45
@available(SwiftStdlib 5.5,*)
46
46
extensionTask{
47
-
/// Returns `true`<!-- FIXME: If this is an abstract, don't include code font or links. --> if the task is canceled<!-- FIXME: Passive; rewrite. -->, and should stop executing.
47
+
/// A Boolean value that indicates whether the task should stop executing.
48
+
///
49
+
/// After the value of this property becomes `true`, it remains `true` indefinitely.
/// Returns `true` if the task is canceled, and should stop executing.<!-- FIXME: Abstracts need to be unique; this is copy/pasted from what's on line 47, which means it carries the same problems. Rewrite the abstract so that this is different from the one on line 47. What sets it apart? Why would someone use this over the previous? -->
66
+
/// A Boolean value that indicates whether the task should stop executing.
64
67
///
65
-
/// If no current `Task` is available, returns `false`, as outside of a task
66
-
/// context no task cancellation may be observed<!-- FIXME: Passive; rewrite. -->.
68
+
/// After the value of this property becomes `true`, it remains `true` indefinitely.
69
+
/// There is no way to uncancel a task.
67
70
///
68
71
/// - SeeAlso: `checkCancellation()`
69
72
publicstaticvarisCancelled:Bool{
@@ -75,7 +78,7 @@ extension Task where Success == Never, Failure == Never {
/// Check if the task is canceled<!-- FIXME: Passive; rewrite. --> and throw an `CancellationError`<!-- FIXME: Don't include symbols in abstracts. --> if it was.
81
+
/// Throws an error if the task was canceled.
79
82
///
80
83
/// The error is always an instance of `Task.CancellationError`.
81
84
///
@@ -87,10 +90,10 @@ extension Task where Success == Never, Failure == Never {
87
90
}
88
91
}
89
92
90
-
/// The default cancellation thrown when a task is canceled<!-- FIXME: Passive; rewrite. -->.
93
+
/// An error that indicates a task was canceled.
91
94
///
92
95
/// This error is also thrown automatically by `Task.checkCancellation()`,
93
-
/// if the current task has been canceled<!-- FIXME: Passive; rewrite. -->.
96
+
/// if the current task has been canceled.
94
97
@available(SwiftStdlib 5.5,*)
95
98
publicstructCancellationError:Error{
96
99
// no extra information, cancellation is intended to be light-weight
0 commit comments