Files
swift-mirror/test/Concurrency/Runtime/async_taskgroup_is_asyncsequence.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

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.5, *)
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.5, *)
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.5, *)
@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
}
}