emit method
Emits the event, calling all registered listeners.
This method executes all synchronous listeners first, then all asynchronous listeners. Asynchronous listeners are awaited, so this method will not complete until all listeners have finished executing.
Parameters:
data
- The data to pass to all listeners
Returns the total number of listeners that were executed.
Example:
int listenerCount = await event.emit(userData);
print('$listenerCount listeners were notified');
Implementation
Future<int> emit([dynamic data]) async {
var i = 0;
for (var listener in _listeners) {
listener(data);
i++;
}
for (var asyncListener in _asyncListeners) {
await asyncListener(data);
i++;
}
return i;
}