Skip to content

Commit 737962e

Browse files
authored
[Concurrency] SR-15309: Fix instance task.isCancelled impl to use _task (swiftlang#39710)
1 parent adb11ec commit 737962e

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

stdlib/public/Concurrency/TaskCancellation.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff 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

test/Concurrency/Runtime/async_task_handle_cancellation.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,22 @@
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
}

0 commit comments

Comments
 (0)