Files
swift-mirror/test/Concurrency/Runtime/async_taskgroup_is_asyncsequence.swift
2021-02-22 13:26:33 +09:00

45 lines
811 B
Swift

// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency -parse-as-library) | %FileCheck %s --dump-input=always
// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: libdispatch
import Dispatch
#if canImport(Darwin)
import Darwin
#elseif canImport(Glibc)
import Glibc
#endif
func test_taskGroup_is_asyncSequence() async {
let sum: Int = try! await Task.withGroup(resultType: Int.self) { group in
for n in 1...10 {
await group.add {
print("add \(n)")
return n
}
}
var sum = 0
for try await r in group { // here
print("next: \(r)")
sum += r
}
return sum
}
// CHECK: result: 55
print("result: \(sum)")
}
@main struct Main {
static func main()
async {
await test_taskGroup_is_asyncSequence()
}
}