Files
swift-mirror/test/Concurrency/Runtime/async_task_yield.swift
Allan Shortlidge c02fc4724d Tests: Remove -disable-availability-checking from many Concurrency tests.
Instead, use the `%target-swift-5.1-abi-triple` substitution to compile the tests
for deployment to the minimum OS versions required for use of _Concurrency APIs.
2024-10-18 16:21:51 -07:00

51 lines
999 B
Swift

// RUN: %target-run-simple-swift(-target %target-swift-5.1-abi-triple -parse-as-library)
// REQUIRES: executable_test
// REQUIRES: concurrency
// UNSUPPORTED: freestanding
// REQUIRES: concurrency_runtime
// UNSUPPORTED: back_deployment_runtime
@available(SwiftStdlib 5.1, *)
protocol Go: Actor {
func go(times: Int) async -> Int
}
@available(SwiftStdlib 5.1, *)
extension Go {
func go(times: Int) async -> Int {
for i in 0...times {
print("\(Self.self) @ \(i)")
await Task.yield()
}
return times
}
}
@available(SwiftStdlib 5.1, *)
actor One: Go {}
@available(SwiftStdlib 5.1, *)
actor Two: Go {}
@available(SwiftStdlib 5.1, *)
func yielding() async {
let one = One()
let two = Two()
await withTaskGroup(of: Int.self) { group in
group.addTask {
await one.go(times: 100)
}
group.addTask {
await two.go(times: 100)
}
}
}
@available(SwiftStdlib 5.1, *)
@main struct Main {
static func main() async {
await yielding()
}
}