emitAsync method

Future<void> emitAsync(
  1. Object? instance,
  2. Enum eventName, [
  3. dynamic param
])

Trigger eventName event with or without the param given as async way.

Implementation

Future<void> emitAsync(
  Object? instance,
  Enum eventName, [
  dynamic param,
]) async {
  final callbacks = {
    ...?_events[_getEventKey(instance, eventName)],
    ...?_events["${instance.hashCode}.${eventName.hashCode}"],
  };

  await Future.wait(
    callbacks.map(
      (callback) => Future.microtask(
        () => callback(_getInstance(instance), param),
      ),
    ),
  );
}