mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
handler of parent task that created the group Change comment in TaskGroup.swift to enforce that only parent task can call cancelAll on the group Add tests to verify mutating of task group in child tasks will fail Radar-Id: rdar://problem/86346865
41 lines
1.1 KiB
Swift
41 lines
1.1 KiB
Swift
// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking %import-libdispatch -parse-as-library) | %FileCheck %s
|
|
|
|
// REQUIRES: executable_test
|
|
// REQUIRES: concurrency
|
|
// REQUIRES: libdispatch
|
|
|
|
// rdar://76038845
|
|
// REQUIRES: concurrency_runtime
|
|
// UNSUPPORTED: back_deployment_runtime
|
|
|
|
func test_taskGroup_cancelAll() async {
|
|
|
|
await withTaskCancellationHandler {
|
|
await withTaskGroup(of: Int.self, returning: Void.self) { group in
|
|
group.spawn {
|
|
await Task.sleep(3_000_000_000)
|
|
let c = Task.isCancelled
|
|
print("group task isCancelled: \(c)")
|
|
return 0
|
|
}
|
|
|
|
group.cancelAll() // Cancels the group but not the task
|
|
_ = await group.next()
|
|
}
|
|
} onCancel : {
|
|
print("parent task cancel handler called")
|
|
}
|
|
|
|
// CHECK-NOT: parent task cancel handler called
|
|
// CHECK: group task isCancelled: true
|
|
// CHECK: done
|
|
print("done")
|
|
}
|
|
|
|
@available(SwiftStdlib 5.1, *)
|
|
@main struct Main {
|
|
static func main() async {
|
|
await test_taskGroup_cancelAll()
|
|
}
|
|
}
|