mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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.
52 lines
1.0 KiB
Swift
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()
|
|
}
|
|
}
|