Files
swift-mirror/test/Concurrency/Runtime/async_task_yield.swift
Kuba (Brecka) Mracek 7853184ed6 Enable running tests from test/Concurrency/ directory in freestanding/minimal presets (#61835)
* Enable running tests from test/Concurrency/ directory in freestanding/minimal presets

* Mark failing Concurrency tests as XFAIL/SKIP on freestanding/minimal
2022-11-04 09:07:27 -07:00

51 lines
1004 B
Swift

// RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking -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()
}
}