emitEvent<T extends Event> method

bool emitEvent<T extends Event>(
  1. T event
)

Emits an event to all listeners. This will broadcast the event to all listeners that match the same event type and data type.

  final emitter = EventEmitter();
    ...
  events.emitEvent(Event('message', 'Hello World'));

A custom event can be emitted by extending the Event class. This allows for custom data to be passed to the listeners, it's expected to have the same effect as a normal event.

Implementation

bool emitEvent<T extends Event>(T event) {
  bool allSatisfied = true;
  for (final listener in listeners.toList()) {
    final satisfied = listener.call<T>(event);
    if (!satisfied) allSatisfied = false;
  }
  return allSatisfied;
}