whistle

class AsyncEventDispatcher[source]

Bases: AbstractEventDispatcher

Adapts whiste’s EventDispatcher to be async.

Added in version 2.0.

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

Return type:

IDispatchedEvent

dispatch(event_id, event=None, /)[source]
Parameters:
Return type:

IDispatchedEvent

class Event[source]

Bases: object

Base class to represent whistle’s events. You can subclass this if you want to embed special data and associated logic with your events, or just let the event dispatcher create instances for you

The event handlers will have Event instances passed, so you can bundle any data required by your handlers there.

stop_propagation()[source]

Stop event propagation, meaning that the remaining handlers won’t be called after this one.

dispatcher = None
name = None

Event name placeholder, will be set by dispatcher.

propagation_stopped = False

Has the event propagation ended?

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)

class IAsyncEventDispatcher[source]

Bases: IAbstractEventDispatcher, Protocol

async adispatch(event_id, event=None, /)[source]
Parameters:
Return type:

IDispatchedEvent

class IDispatchedEvent[source]

Bases: IEvent, Protocol

dispatcher: IAbstractEventDispatcher
class IEvent[source]

Bases: Protocol

__init__(*args, **kwargs)
stop_propagation()[source]
name: str
propagation_stopped: bool
class IEventDispatcher[source]

Bases: IAbstractEventDispatcher, Protocol

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

IDispatchedEvent

Submodules