File tree Expand file tree Collapse file tree 1 file changed +4
-13
lines changed Expand file tree Collapse file tree 1 file changed +4
-13
lines changed Original file line number Diff line number Diff line change 99import Dispatch
1010
1111func completeSlowly( n: Int ) async -> Int {
12- await Task . sleep ( UInt64 ( ( n * 1_000_000_000 ) + 1_000_000_000 ) )
13- print ( " complete group.spawn { \( n) } " )
12+ try ? await Task . sleep ( for: . milliseconds( n * 300 ) )
1413 return n
1514}
1615
1716/// Tasks complete AFTER they are next() polled.
1817func test_sum_nextOnPending( ) async {
1918 let numbers = [ 1 , 2 , 3 ]
20- let expected = 6 // FIXME: numbers.reduce(0, +) this hangs?
19+ let expected = 6
2120
2221 let sum = try ! await withTaskGroup ( of: Int . self) { ( group) async -> Int in
2322 for n in numbers {
24- group. spawn {
25- let res = await completeSlowly ( n: n)
26- return res
23+ group. addTask {
24+ await completeSlowly ( n: n)
2725 }
2826 }
2927
@@ -42,13 +40,6 @@ func test_sum_nextOnPending() async {
4240
4341 // The completions are set apart by n seconds, so we expect them to arrive
4442 // in the order as the numbers (and delays) would suggest:
45- //
46- // CHECK: complete group.spawn { 1 }
47- // CHECK: next: 1
48- // CHECK: complete group.spawn { 2 }
49- // CHECK: next: 2
50- // CHECK: complete group.spawn { 3 }
51- // CHECK: next: 3
5243
5344 // CHECK: task group returning: 6
5445
You can’t perform that action at this time.
0 commit comments