addAsyncListener method
Adds an asynchronous listener to the event.
Asynchronous listeners can perform async operations and are awaited during event emission. They are executed after all synchronous listeners have completed.
Parameters:
listener
- The async function to call when the event is emitted
Returns this Event instance for method chaining.
Example:
event.addAsyncListener((data) async => await saveToDatabase(data))
.addAsyncListener((data) async => await sendNotification(data));
Implementation
Event addAsyncListener(EventAsyncFunction listener) {
_asyncListeners.add(listener);
return this;
}