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 @@ -51,13 +51,7 @@ extension Task {
51
51
///
52
52
/// - SeeAlso: `checkCancellation()`
53
53
public var isCancelled : Bool {
54
- withUnsafeCurrentTask { task in
55
- guard let task = task else {
56
- return false
57
- }
58
-
59
- return _taskIsCancelled ( task. _task)
60
- }
54
+ _taskIsCancelled ( _task)
61
55
}
62
56
}
63
57
Original file line number Diff line number Diff line change 17
17
@available ( SwiftStdlib 5 . 5 , * )
18
18
@main struct Main {
19
19
static func main( ) async {
20
- let handle = detach {
20
+ let task = Task . detached {
21
21
while ( !Task. isCancelled) { // no need for await here, yay
22
22
print ( " waiting " )
23
23
}
24
24
25
- print ( " done " )
25
+ print ( " inside: Task.isCancelled = \( Task . isCancelled ) " )
26
26
}
27
27
28
- handle . cancel ( )
28
+ task . cancel ( )
29
29
30
- // CHECK: done
31
- await handle. get ( )
30
+ await task. value
31
+ print ( " outside: task.isCancelled = \( task. isCancelled) " )
32
+ print ( " outside: Task.isCancelled = \( Task . isCancelled) " )
33
+
34
+ // CHECK-DAG: inside: Task.isCancelled = true
35
+ // CHECK-DAG: outside: task.isCancelled = true
36
+ // CHECK-DAG: outside: Task.isCancelled = false
32
37
}
33
38
}
You can’t perform that action at this time.
0 commit comments