IEventListener

An interface for listener objects that receive notifications on fired events.

Description

The IEventListener interface allows you to define actions to be taken by listener objects after receiving a notification on a fired event.

Instance methods

onEvent

A method called when events this listener is subscribed to are fired.

onEvent(context: IContext, event: IEvent, args: Parameters): void

  • context: IContext - a context to trace execution through a call chain
  • event: IEvent - (optional) fired event.
  • args: Parameters - event arguments.

Examples


	see IEvent
	see Event
	Example:
		type MyListener struct {
			msg string
		}

		func (l *MyListener) OnEvent(ctx context.Context, event IEvent, args Parameters) {
			fmt.Println("Fired event " + event.Name())
		}

		var event = NewEvent("myevent")
		_listener := MyListener{}
		event.AddListener(_listener)
		event.Notify(context.Background(), "123", Parameters.FromTuples("param1", "ABC"))

		// Console output: Fired event myevent

See also