mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
The concurrency runtime now deploys back to macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, which corresponds to the 5.1 release of the stdlib. Adjust macro usages accordingly.
72 lines
1.5 KiB
Swift
72 lines
1.5 KiB
Swift
// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -parse-as-library) | %FileCheck %s --dump-input=always
|
|
|
|
// REQUIRES: executable_test
|
|
// REQUIRES: concurrency
|
|
|
|
// rdar://76038845
|
|
// REQUIRES: concurrency_runtime
|
|
// UNSUPPORTED: back_deployment_runtime
|
|
|
|
// UNSUPPORTED: linux
|
|
|
|
@available(SwiftStdlib 5.1, *)
|
|
func test_taskGroup_is_asyncSequence() async {
|
|
print(#function)
|
|
|
|
let sum = await withTaskGroup(of: Int.self, returning: Int.self) { group in
|
|
for n in 1...10 {
|
|
group.spawn {
|
|
print("add \(n)")
|
|
return n
|
|
}
|
|
}
|
|
|
|
var sum = 0
|
|
for await r in group { // here
|
|
print("next: \(r)")
|
|
sum += r
|
|
}
|
|
|
|
return sum
|
|
}
|
|
|
|
print("result: \(sum)")
|
|
}
|
|
|
|
@available(SwiftStdlib 5.1, *)
|
|
func test_throwingTaskGroup_is_asyncSequence() async throws {
|
|
print(#function)
|
|
|
|
let sum = try await withThrowingTaskGroup(of: Int.self, returning: Int.self) { group in
|
|
for n in 1...10 {
|
|
group.spawn {
|
|
print("add \(n)")
|
|
return n
|
|
}
|
|
}
|
|
|
|
var sum = 0
|
|
for try await r in group { // here
|
|
print("next: \(r)")
|
|
sum += r
|
|
}
|
|
|
|
return sum
|
|
}
|
|
|
|
print("result: \(sum)")
|
|
}
|
|
|
|
@available(SwiftStdlib 5.1, *)
|
|
@main struct Main {
|
|
static func main() async {
|
|
await test_taskGroup_is_asyncSequence()
|
|
// CHECK: test_taskGroup_is_asyncSequence()
|
|
// CHECK: result: 55
|
|
|
|
try! await test_throwingTaskGroup_is_asyncSequence()
|
|
// CHECK: test_throwingTaskGroup_is_asyncSequence()
|
|
// CHECK: result: 55
|
|
}
|
|
}
|