call method

  1. @override
Map<int, CallbackReturnType> call(
  1. CallbackInputType input
)
override

Make the handler callable as a function.

Mutating the handler from inside a callback is safe. A callback unregistered during the dispatch does not run if its turn has not come yet; one registered during the dispatch runs from the next dispatch onwards. No other callback is ever skipped as a side effect.

A callback that throws is reported through onError (or to the current Zone) and contributes no entry to the returned map, while the remaining callbacks still run.

Implementation

@override
Map<int, CallbackReturnType> call(CallbackInputType input) {
  final ids = List<int>.of(_keys);

  final results = <int, CallbackReturnType>{};
  for (final id in ids) {
    final callback = map.get(id);
    if (callback == null) continue;
    try {
      results[id] = callback.call(input);
      // ignore: avoid_catches_without_on_clauses
    } catch (error, stackTrace) {
      final handler = onError;
      if (handler != null) {
        handler(error, stackTrace);
      } else {
        Zone.current.handleUncaughtError(error, stackTrace);
      }
    }
  }
  return results;
}