@@ -216,32 +216,33 @@ or with an error if any of the provided futures fail.
216216
217217### Handling errors for multiple futures
218218
219- You can also wait for parallel operations on an [ iterable] ( {{site.dart-api}}/dart-async/FutureIterable/wait.html )
220- or [ record] ( {{site.dart-api}}/dart-async/FutureRecord2/wait.html )
221- of futures.
219+ You can also wait for parallel operations on:
222220
223- These extensions return a future with the resulting values of all provided
224- futures. Unlike ` Future.wait ` , they also let you handle errors.
221+ * An [ iterable ] [ iterable-futures ] of futures
222+ * A [ record ] [ record-futures ] with futures as positional fields
225223
226- If any future in the collection completes with an error, ` wait ` completes with a
227- [ ` ParallelWaitError ` ] [ ] . This allows the caller to handle individual errors and
228- dispose successful results if necessary .
224+ These extensions return a ` Future ` with the
225+ resulting values of all provided futures.
226+ Unlike ` Future.wait ` , they also let you handle errors .
229227
230- When you _ don't_ need the result values from each individual future,
228+ If any future in the collection completes with an error,
229+ ` wait ` completes with a [ ` ParallelWaitError ` ] [ ] .
230+ This allows the caller to handle individual errors and
231+ dispose of successful results if necessary.
232+
233+ When you _ don't_ need the result values from each future,
231234use ` wait ` on an _ iterable_ of futures:
232235
233236``` dart
237+ Future<int> delete() async => ...;
238+ Future<String> copy() async => ...;
239+ Future<bool> errorResult() async => ...;
240+
234241void main() async {
235- Future<void> delete() async => ...
236- Future<void> copy() async => ...
237- Future<void> errorResult() async => ...
238-
239242 try {
240243 // Wait for each future in a list, returns a list of futures:
241244 var results = await [delete(), copy(), errorResult()].wait;
242-
243- } on ParallelWaitError<List<bool?>, List<AsyncError?>> catch (e) {
244-
245+ } on ParallelWaitError<List<bool?>, List<AsyncError?>> catch (e) {
245246 print(e.values[0]); // Prints successful future
246247 print(e.values[1]); // Prints successful future
247248 print(e.values[2]); // Prints null when the result is an error
@@ -250,7 +251,6 @@ void main() async {
250251 print(e.errors[1]); // Prints null when the result is successful
251252 print(e.errors[2]); // Prints error
252253 }
253-
254254}
255255```
256256
@@ -259,27 +259,30 @@ use `wait` on a _record_ of futures.
259259This provides the additional benefit that the futures can be of different types:
260260
261261``` dart
262+ Future<int> delete() async => ...;
263+ Future<String> copy() async => ...;
264+ Future<bool> errorResult() async => ...;
265+
262266void main() async {
263- Future<int> delete() async => ...
264- Future<String> copy() async => ...
265- Future<bool> errorResult() async => ...
266-
267- try {
268- // Wait for each future in a record, returns a record of futures:
269- (int, String, bool) result = await (delete(), copy(), errorResult()).wait;
270-
271- } on ParallelWaitError<(int?, String?, bool?),
272- (AsyncError?, AsyncError?, AsyncError?)> catch (e) {
267+ try {
268+ // Wait for each future in a record.
269+ // Returns a record of futures that you can destructure.
270+ final (deleteInt, copyString, errorBool) =
271+ await (delete(), copy(), errorResult()).wait;
272+
273+ // Do something with the results...
274+ } on ParallelWaitError<
275+ (int?, String?, bool?),
276+ (AsyncError?, AsyncError?, AsyncError?)
277+ > catch (e) {
273278 // ...
274- }
275-
276- // Do something with the results:
277- var deleteInt = result.$1;
278- var copyString = result.$2;
279- var errorBool = result.$3;
279+ }
280280}
281281```
282282
283+ [ iterable-futures ] : {{site.dart-api}}/dart-async/FutureIterable/wait.html
284+ [ record-futures ] : {{site.dart-api}}/dart-async/FutureRecord2/wait.html
285+
283286## Stream
284287
285288Stream objects appear throughout Dart APIs, representing sequences of
0 commit comments