Event

Concrete implementation of the IEvent interface.

Implements: IEvent

Description

The Event class allows you to create events.

Important points

  • It allows you to send asynchronous notifications to multiple subscribed listeners.

Constructors

Creates a new event and assigns its name.
Throws an Error if the name is null.

Event(String name)

  • name: String - name of the event that is to be created.

Instance methods

addListener

Adds a listener to receive notifications when this event is fired.

@override

void addListener(IEventListener listener)

getListeners

Gets all listeners registred in this event.

@override

List<IEventListener> getListeners()

getName

Gets the name of the event.

@override

String getName()

  • returns: String - name of this event.

notify

Fires this event and notifies all registred listeners.
Throws an InvocationException if the event fails to be raised.

@override

void notify(IContext? context, Parameters args)

  • context: IContext - (optional) a context to trace execution through a call chainn.
  • args: Parameters - parameters to raise this event with.

RemoveListener

Removes a listener, so that it no longer receives notifications for this event.

@override

void removeListener(IEventListener listener)

Example:

var event =  Event('my_event');
event.addListener(myListener);

event.notify('123', Parameters.fromTuples(
  ['param1', 'ABC',
  'param2', 123]
));

See also