Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Replace Future.wait with Iterable<Future>.wait #188

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/aggregate_sample.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ extension AggregateSample<T> on Stream<T> {
// Handle opt-out nulls
cancels.removeWhere((Object? f) => f == null);
if (cancels.isEmpty) return null;
return Future.wait(cancels).then((_) => null);
return cancels.wait.then((_) => null);
Copy link
Contributor

@lrhn lrhn Jun 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could all these (_) => null use the same top-level helper function, void voidCallback(void _) {}?
That should ensure we only have one function instance, instead of one per call point.

};
};
return controller.stream;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/async_expand.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ extension AsyncExpand<T> on Stream<T> {
var cancels = [for (var s in subscriptions) s.cancel()]
// Handle opt-out nulls
..removeWhere((Object? f) => f == null);
return Future.wait(cancels).then((_) => null);
return cancels.wait.then((_) => null);
};
};
return controller.stream;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/combine_latest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ extension CombineLatest<T> on Stream<T> {
..removeWhere((Object? f) => f == null);
sourceSubscription = null;
otherSubscription = null;
return Future.wait(cancels).then((_) => null);
return cancels.wait.then((_) => null);
};
};
return controller.stream;
Expand Down Expand Up @@ -234,7 +234,7 @@ extension CombineLatest<T> on Stream<T> {
// Handle opt-out nulls
..removeWhere((Object? f) => f == null);
if (cancels.isEmpty) return null;
return Future.wait(cancels).then((_) => null);
return cancels.wait.then((_) => null);
};
};
return controller.stream;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/merge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ extension Merge<T> on Stream<T> {
// Handle opt-out nulls
..removeWhere((Object? f) => f == null);
if (cancels.isEmpty) return null;
return Future.wait(cancels).then((_) => null);
return cancels.wait.then((_) => null);
};
};
return controller.stream;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ extension SwitchLatest<T> on Stream<Stream<T>> {
// Handle opt-out nulls
..removeWhere((Object? f) => f == null);
if (cancels.isEmpty) return null;
return Future.wait(cancels).then(_ignore);
return cancels.wait.then(_ignore);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be (_) => null like the rest, or use the same helper function.

};
};
return controller.stream;
Expand Down
2 changes: 1 addition & 1 deletion test/scan_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void main() {
const TypeMatcher<Future<void>>(),
const TypeMatcher<Future<void>>()
]);
expect(await Future.wait(result), [1, 3]);
expect(await result.wait, [1, 3]);
});

test('does not call for subsequent values while waiting', () async {
Expand Down