on abstract method

void on(
  1. String event,
  2. EventListener listener, {
  3. EventPriority priority = EventPriority.normal,
  4. bool once = false,
  5. Object? subscriber,
})

Registers a listener for a specific event.

  • event: The name of the event (e.g., 'user.created').
  • listener: The function to call when the event is emitted.
  • priority: Execution order; higher priority listeners run first.
  • once: If true, the listener is removed after one execution.
  • subscriber: Optional object to associate with the listener for bulk removal.

Listeners are executed in priority order when the event is emitted. If subscriber is provided, it's tracked for offSubscriber cleanup.

Example:

events.on('order.placed', handleOrder, priority: EventPriority.high, subscriber: this);

Implementation

void on(
  String event,
  EventListener listener, {
  EventPriority priority = EventPriority.normal,
  bool once = false,
  Object? subscriber,
});