File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,32 @@ func test_throwingTaskGroup_is_asyncSequence() async throws {
55
55
print ( " result: \( sum) " )
56
56
}
57
57
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
+
58
84
@available ( SwiftStdlib 5 . 1 , * )
59
85
@main struct Main {
60
86
static func main( ) async {
@@ -65,5 +91,9 @@ func test_throwingTaskGroup_is_asyncSequence() async throws {
65
91
try ! await test_throwingTaskGroup_is_asyncSequence ( )
66
92
// CHECK: test_throwingTaskGroup_is_asyncSequence()
67
93
// CHECK: result: 55
94
+
95
+ await test_asyncSequence_labelledTuples ( )
96
+ // CHECK: test_asyncSequence_labelledTuples()
97
+ // CHECK: result: 65
68
98
}
69
99
}
You can’t perform that action at this time.
0 commit comments