diff --git a/lib/analytics_x.dart b/lib/analytics_x.dart index 76bba04..1dfda06 100644 --- a/lib/analytics_x.dart +++ b/lib/analytics_x.dart @@ -16,14 +16,13 @@ class AnalyticsX { AnalyticsX._internal(); Future init(List vendors) async { - final newVendors = List.from(vendors).toSet().difference(_vendors.toSet()).toList(); + final newVendors = List.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)); } @@ -31,9 +30,7 @@ class AnalyticsX { Future invokeAction(AnalyticsAction action, [List vendorIds = ALL]) async { final List 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 _filterVendors(List vendorIds) {