Skip to content

Commit 69d3933

Browse files
authored
Merge pull request #68601 from kavon/test-coverage-labelled-tuples
[test] add coverage for for-await over labelled tuples
2 parents 469a614 + 7f3eb27 commit 69d3933

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/Concurrency/Runtime/async_taskgroup_is_asyncsequence.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,32 @@ func test_throwingTaskGroup_is_asyncSequence() async throws {
5555
print("result: \(sum)")
5656
}
5757

58+
typealias LabelledTuple = (x: Int, y: Int)
59+
60+
@available(SwiftStdlib 5.1, *)
61+
func test_asyncSequence_labelledTuples() async {
62+
print(#function)
63+
64+
let sum = await withTaskGroup(of: LabelledTuple.self, returning: Int.self) { group in
65+
for n in 1...10 {
66+
group.spawn {
67+
print("add (x: \(n), y: 1)")
68+
return (x: n, y: 1)
69+
}
70+
}
71+
72+
var sum = 0
73+
for await (x, y) in group { // here
74+
print("next: (x:\(x), y:\(y))")
75+
sum += x + y
76+
}
77+
78+
return sum
79+
}
80+
81+
print("result: \(sum)")
82+
}
83+
5884
@available(SwiftStdlib 5.1, *)
5985
@main struct Main {
6086
static func main() async {
@@ -65,5 +91,9 @@ func test_throwingTaskGroup_is_asyncSequence() async throws {
6591
try! await test_throwingTaskGroup_is_asyncSequence()
6692
// CHECK: test_throwingTaskGroup_is_asyncSequence()
6793
// CHECK: result: 55
94+
95+
await test_asyncSequence_labelledTuples()
96+
// CHECK: test_asyncSequence_labelledTuples()
97+
// CHECK: result: 65
6898
}
6999
}

0 commit comments

Comments
 (0)