Skip to content

Commit

Permalink
Run methods on each AnalyticsVendor in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Caseley committed Aug 23, 2021
1 parent 32d8a75 commit 3851d93
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/analytics_x.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,21 @@ class AnalyticsX {
AnalyticsX._internal();

Future<void> init(List<AnalyticsVendor> vendors) async {
final newVendors = List.from(vendors).toSet().difference(_vendors.toSet()).toList();
final newVendors = List<AnalyticsVendor>.from(vendors)..removeWhere((v) => _vendors.contains(v));

if (newVendors.isEmpty) {
return;
}

for (final vendor in newVendors) {
await vendor.init();
}
await Future.wait(newVendors.map((vendor) => vendor.init())); //Do all the inits in parallel

_vendors.addAll(List.from(newVendors));
}

Future<void> invokeAction(AnalyticsAction action, [List<String> vendorIds = ALL]) async {
final List<AnalyticsVendor> vendorsToUse = _filterVendors(vendorIds);

for (final vendor in vendorsToUse) {
await vendor.handleAction(action);
}
await Future.wait(vendorsToUse.map((vendor) => vendor.handleAction(action))); //Do all the actions in parallel
}

List<AnalyticsVendor> _filterVendors(List<String> vendorIds) {
Expand Down

0 comments on commit 3851d93

Please sign in to comment.