Skip to content

Commit 48f9ce5

Browse files
authored
Update 0317-async-let.md (#2390)
Fix the mistake in the code sample, found by Ole Begemann: https://forums.swift.org/t/whats-the-expected-behavior-of-throwing-taskgroup-next-on-cancellation/62211/5 I've tested this and can verify the cancelAll is required to get the correct behaviour.
1 parent 154bb22 commit 48f9ce5

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

proposals/0317-async-let.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,9 @@ func race(left: () async -> Int, right: () async -> Int) async -> Int {
497497
group.async { left() }
498498
group.async { right() }
499499

500-
return await group.next()! // !-safe, there is at-least one result to collect
500+
let first = await group.next()! // !-safe, there is at-least one result to collect
501+
group.cancelAll() // cancel the other task
502+
return first
501503
}
502504
}
503505
```

0 commit comments

Comments
 (0)