whistle.dispatchers.synchronous

class EventDispatcher[source]

Bases: AbstractEventDispatcher

Main class of the library, it is responsible for keeping track of registered listeners, and dispatching events to them. All listeners are scoped to the event dispatcher instance, so you can have multiple event dispatchers with different sets of listeners.

add_listener(event_id, listener, /, *, priority=0)[source]
Parameters:
async adispatch(event_id, event=None, /)[source]
Parameters:
Return type:

IDispatchedEvent

dispatch(event_id, event=None, /)[source]

Dispatch the given event, with the given event id.

An optional event can be given, and should respect the whistle.protocols.IEvent protocol. If no event is given, a new whistle.event.Event instance is created and used.

Returns the event instance after it has been dispatched, whether it has been created or provided by the caller.

Parameters:
  • event_id (str) – hashable identifier for the event

  • event (IEvent | None) – optional event instance

Returns:

the event instance after it has been dispatched

Return type:

IDispatchedEvent

do_dispatch(listeners, event, /)[source]
Parameters:

event (IEvent)