Skip to content

Commit aa75c4e

Browse files
ktosoDougGregor
authored andcommitted
[Concurrency] SR-15309: Fix instance task.isCancelled impl to use _task (#39710)
(cherry picked from commit 737962e)
1 parent 34b9ba9 commit aa75c4e

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
@@ -51,13 +51,7 @@ extension Task {
5151
///
5252
/// - SeeAlso: `checkCancellation()`
5353
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)
6155
}
6256
}
6357

test/Concurrency/Runtime/async_task_handle_cancellation.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,22 @@
1717
@available(SwiftStdlib 5.5, *)
1818
@main struct Main {
1919
static func main() async {
20-
let handle = detach {
20+
let task = Task.detached {
2121
while (!Task.isCancelled) { // no need for await here, yay
2222
print("waiting")
2323
}
2424

25-
print("done")
25+
print("inside: Task.isCancelled = \(Task.isCancelled)")
2626
}
2727

28-
handle.cancel()
28+
task.cancel()
2929

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
3237
}
3338
}

0 commit comments

Comments
 (0)