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.

public constructor(name: string)

  • 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.

public addListener(listener: IEventListener): void

getListeners

Gets all listeners registred in this event.

public getListeners(): IEventListener[]

getName

Gets the name of the event.

public getName(): string

  • returns: string - name of this event.

notify

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

publicnotify(context: IContext, args: Parameters): void

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

removeListener

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

public removeListener(listener: IEventListener): void

Example

event: = NewEvent("my_event");
event.AddListener(myListener);
event.Notify(cpntext.Backgroudn(),
          Parameters.fromTuples(
                 "param1", "ABC",
                  "param2", 123,
           )
);

See also