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 {
46
46
///
47
47
/// - SeeAlso: `checkCancellation()`
48
48
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)
56
50
}
57
51
}
58
52
Original file line number Diff line number Diff line change 10
10
@available ( SwiftStdlib 5 . 5 , * )
11
11
@main struct Main {
12
12
static func main( ) async {
13
- let handle = detach {
13
+ let task = Task . detached {
14
14
while ( !Task. isCancelled) { // no need for await here, yay
15
15
print ( " waiting " )
16
16
}
17
17
18
- print ( " done " )
18
+ print ( " inside: Task.isCancelled = \( Task . isCancelled ) " )
19
19
}
20
20
21
- handle . cancel ( )
21
+ task . cancel ( )
22
22
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
25
30
}
26
31
}
You can’t perform that action at this time.
0 commit comments