@@ -194,18 +194,29 @@ extension Task {
194
194
}
195
195
}
196
196
197
- /// Indicates that the task should stop running .
197
+ /// Marks this task as cancelled .
198
198
///
199
199
/// Task cancellation is cooperative:
200
200
/// a task that supports cancellation
201
- /// checks whether it has been canceled at various points during its work.
201
+ /// checks whether it has been canceled at various points during its work,
202
+ /// and may either return early or throw an error in order to
203
+ /// finish running earlier than it would if it wasn't cancelled.
204
+ ///
205
+ /// Calling this method only has the effect of setting the cancelled
206
+ /// flag on the task (or its child tasks), and unless the tasks itself
207
+ /// react on this flag, there is no observable runtime behavior change
208
+ /// of the tasks. Specifically, tasks are never "interrupted and stopped"
209
+ /// forcefully, and are always allowed to execute code until returning or throwing/
202
210
///
203
- /// Calling this method on a task that doesn't support cancellation
204
- /// has no effect.
205
211
/// Likewise, if the task has already run
206
212
/// past the last point where it would stop early,
207
213
/// calling this method has no effect.
208
214
///
215
+ /// It is safe to call `cancel` from any task or thread.
216
+ /// The `cancel` call is idempotent, and may be called multiple times,
217
+ /// and cancellation handlers will trigger only a single (first)
218
+ /// time the task is cancelled.
219
+ ///
209
220
/// - SeeAlso: `Task.checkCancellation()`
210
221
public func cancel( ) {
211
222
Builtin . cancelAsyncTask ( _task)
0 commit comments