EventManager
Hierarchy
- EventManager
Index
Methods
__aenter__
Initialize the event manager upon entering the async context.
Returns Self
__aexit__
Close the event manager upon exiting the async context.
This will stop listening for the events, and it will wait for all the event listeners to finish.
Parameters
exc_type: type[BaseException] | None
exc_value: BaseException | None
exc_traceback: TracebackType | None
Returns None
__init__
Initialize a new instance.
Parameters
optionalkeyword-onlypersist_state_interval: timedelta = timedelta(minutes=1)
Interval between emitted
PersistStateevents to maintain state persistence.optionalkeyword-onlyclose_timeout: timedelta | None = None
Optional timeout for canceling pending event listeners if they exceed this duration.
Returns None
emit
Emit an event with the associated data to all registered listeners.
Each listener is invoked in its own task, so this method only starts them. Use
wait_for_all_listeners_to_completeto wait for them to finish.Parameters
keyword-onlyevent: Event
The event which will be emitted.
keyword-onlyevent_data: EventData
The data which will be passed to the event listeners.
Returns None
off
Remove a specific listener or all listeners for an event.
Parameters
keyword-onlyevent: Event
The Actor event for which to remove listeners.
optionalkeyword-onlylistener: EventListener[Any] | None = None
The listener which is supposed to be removed. If not passed, all listeners of this event are removed.
Returns None
on
Register an event listener for a specific event.
Parameters
keyword-onlyevent: Event
The event for which to listen to.
keyword-onlylistener: EventListener[Any]
The function (sync or async) which is to be called when the event is emitted.
Returns None
wait_for_all_listeners_to_complete
Wait for all currently executing event listeners to complete.
Parameters
optionalkeyword-onlytimeout: timedelta | None = None
The maximum time to wait for the event listeners to finish. If they do not complete within the specified timeout, they will be canceled.
Returns None
Properties
active
Indicate whether the context is active.
Manage events and their listeners, enabling registration, emission, and execution control.
Listeners can be registered for any of the events and are invoked whenever the event is emitted, each of them in its own task - the sync ones in a separate thread so that they cannot block the event loop. On top of that, it emits
PersistStateevents at regular intervals and can wait for all the running listeners to complete.