Files
swift-mirror/test/Concurrency/Runtime/async_task_yield.swift
Doug Gregor 3ee09a2298 Switch concurrency runtime tests to "REQUIRES: concurrency_runtime"
Rather than blanket-disabling concurrency tests when we aren't using a
just-built concurrency library, enable them whenever we have a
suitable concurrency runtime, either just-built, in the OS, or via the
back-deployment libraries.
2021-09-13 12:34:20 -07:00

52 lines
1.0 KiB
Swift

// RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking -parse-as-library)
// REQUIRES: executable_test
// REQUIRES: concurrency
// https://bugs.swift.org/browse/SR-14333
// UNSUPPORTED: OS=windows-msvc
// REQUIRES: concurrency_runtime
// UNSUPPORTED: back_deployment_runtime
@available(SwiftStdlib 5.5, *)
protocol Go: Actor {
func go(times: Int) async -> Int
}
@available(SwiftStdlib 5.5, *)
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.5, *)
actor One: Go {}
@available(SwiftStdlib 5.5, *)
actor Two: Go {}
@available(SwiftStdlib 5.5, *)
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.5, *)
@main struct Main {
static func main() async {
await yielding()
}
}