Source code for whistle.typing.dispatcher

from typing import Optional, Protocol

from .event import IEvent
from .listener import IListener


[docs] class IAbstractEventDispatcher(Protocol):
[docs] def get_listeners(self, event_id: Optional[str] = None, /): ...
[docs] def has_listeners(self, event_id: Optional[str] = None, /): ...
[docs] def add_listener(self, event_id: str, listener: IListener, /, *, priority: int = 0): ...
[docs] def remove_listener(self, event_id: str, listener: IListener, /): ...
[docs] class IDispatchedEvent(IEvent, Protocol): # todo: add typed var for event dispatcher type dispatcher: IAbstractEventDispatcher
[docs] class IEventDispatcher(IAbstractEventDispatcher, Protocol):
[docs] def dispatch(self, event_id, event=None, /) -> IDispatchedEvent: ...
[docs] class IAsyncEventDispatcher(IAbstractEventDispatcher, Protocol):
[docs] async def adispatch(self, event_id: str, event: Optional[IEvent] = None, /) -> IDispatchedEvent: ...