callAll method

Future<Map> callAll(
  1. T1 param, {
  2. Set? include,
  3. Set exclude = const {},
  4. dynamic onError(
    1. Object e
    )?,
})

Invokes the appripriate callbacks in the collection.

  • param Specify a parameter to pass to the callbacks.
  • include Specify which callbacks to invoke. Set to null to include all callbacks.
  • exclude Specify which callbacks to exclude from invocation.
  • onError Specify a callback to execute if an error occurs.

Returns a map where each key corresponds to a callback's key and its associated result.

Implementation

Future<Map<dynamic, dynamic>> callAll(
  T1 param, {
  Set<dynamic>? include,
  Set<dynamic> exclude = const {},
  dynamic Function(Object e)? onError,
}) async {
  return this._queue.add(() async {
    final results = <dynamic, dynamic>{};
    var entries = this._callbacks.entries;
    if (include != null) {
      entries = entries.where((e) => include.contains(e.key));
    }
    if (exclude.isNotEmpty) {
      entries = entries.where((e) => !exclude.contains(e.key));
    }
    for (final entry in entries) {
      final key = entry.key;
      final function = entry.value;
      try {
        results[key] = await function(key, param);
      } catch (e) {
        if (onError != null) {
          results[key] = onError(e);
        } else {
          rethrow;
        }
      }
    }
    return results;
  });
}