Skip to content

Commit 22c0887

Browse files
authored
Merge pull request #37108 from ktoso/wip-async_task_async_let_child_cancel-without-sleep
[Concurrency] Harden async_task_async_let_child_cancel so it does not need sleep
2 parents 910a741 + d9a952a commit 22c0887

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Diff for: test/Concurrency/Runtime/async_task_async_let_child_cancel.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ func printWaitPrint(_ int: Int) async -> Int {
1818

1919
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
2020
func test() async {
21+
let h = detach {
22+
await printWaitPrint(0)
23+
}
24+
2125
let handle = detach {
2226
print("detached run, cancelled:\(Task.isCancelled)")
2327

@@ -27,6 +31,8 @@ func test() async {
2731
async let two = printWaitPrint(2)
2832
print("spawned: 2")
2933

34+
h.cancel()
35+
3036
let first = await one
3137
print("awaited: 1: \(first)")
3238
let second = await two
@@ -40,7 +46,7 @@ func test() async {
4046
print("exit detach")
4147
}
4248

43-
await Task.sleep(2 * 1_000_000)
49+
await h.get()
4450

4551
print("cancel")
4652
handle.cancel()

0 commit comments

Comments
 (0)