File tree Expand file tree Collapse file tree 2 files changed +11
-12
lines changed
stdlib/public/Concurrency Expand file tree Collapse file tree 2 files changed +11
-12
lines changed Original file line number Diff line number Diff line change @@ -46,13 +46,7 @@ extension Task {
4646 ///
4747 /// - SeeAlso: `checkCancellation()`
4848 public var isCancelled : Bool {
49- withUnsafeCurrentTask { task in
50- guard let task = task else {
51- return false
52- }
53-
54- return _taskIsCancelled ( task. _task)
55- }
49+ _taskIsCancelled ( _task)
5650 }
5751}
5852
Original file line number Diff line number Diff line change 1010@available ( SwiftStdlib 5 . 5 , * )
1111@main struct Main {
1212 static func main( ) async {
13- let handle = detach {
13+ let task = Task . detached {
1414 while ( !Task. isCancelled) { // no need for await here, yay
1515 print ( " waiting " )
1616 }
1717
18- print ( " done " )
18+ print ( " inside: Task.isCancelled = \( Task . isCancelled ) " )
1919 }
2020
21- handle . cancel ( )
21+ task . cancel ( )
2222
23- // CHECK: done
24- await handle. get ( )
23+ await task. value
24+ print ( " outside: task.isCancelled = \( task. isCancelled) " )
25+ print ( " outside: Task.isCancelled = \( Task . isCancelled) " )
26+
27+ // CHECK-DAG: inside: Task.isCancelled = true
28+ // CHECK-DAG: outside: task.isCancelled = true
29+ // CHECK-DAG: outside: Task.isCancelled = false
2530 }
2631}
You can’t perform that action at this time.
0 commit comments