@@ -695,8 +695,8 @@ To let the user stop this work,
695
695
without waiting for all of the tasks to complete,
696
696
the tasks need check for cancellation and stop running if they are canceled.
697
697
There are two ways a task can do this:
698
- by calling the [ ` Task.checkCancellation() ` ] [ ] method,
699
- or by reading the [ ` Task.isCancelled ` ] [ ] property.
698
+ by calling the [ ` Task.checkCancellation() ` ] [ ] type method,
699
+ or by reading the [ ` Task.isCancelled ` ] [ `Task.isCancelled` type ] type property.
700
700
Calling ` checkCancellation() ` throws an error if the task is canceled;
701
701
a throwing task can propagate the error out of the task,
702
702
stopping all of the task's work.
@@ -706,7 +706,7 @@ which lets you perform clean-up work as part of stopping the task,
706
706
like closing network connections and deleting temporary files.
707
707
708
708
[ `Task.checkCancellation()` ] : https://developer.apple.com/documentation/swift/task/3814826-checkcancellation
709
- [ `Task.isCancelled` ] : https://developer.apple.com/documentation/swift/task/3814832- iscancelled
709
+ [ `Task.isCancelled` type ] : https://developer.apple.com/documentation/swift/task/iscancelled-swift.type.property
710
710
711
711
```
712
712
let photos = await withTaskGroup(of: Optional<Data>.self) { group in
@@ -745,6 +745,13 @@ The code above makes several changes from the previous version:
745
745
746
746
[ `TaskGroup.addTaskUnlessCancelled(priority:operation:)` ] : https://developer.apple.com/documentation/swift/taskgroup/addtaskunlesscancelled(priority:operation:)
747
747
748
+ > Note:
749
+ > To check whether a task has been canceled from outside that task,
750
+ > use the [ ` Task.isCancelled ` ] [ `Task.isCancelled` instance ] instance property
751
+ > instead of the type property.
752
+
753
+ [ `Task.isCancelled` instance ] : https://developer.apple.com/documentation/swift/task/iscancelled-swift.property
754
+
748
755
For work that needs immediate notification of cancellation,
749
756
use the [ ` Task.withTaskCancellationHandler(operation:onCancel:) ` ] [ ] method.
750
757
For example:
0 commit comments