Skip to main content

EventManager

Event manager for registering, emitting, and managing event listeners.

Event manager allows you to register event listeners, emit events, and wait for event listeners to complete their execution. It is built on top of the pyee.asyncio.AsyncIOEventEmitter class.

Hierarchy

Index

Methods

__aenter__

  • Initializes the event manager upon entering the async context.


    Returns EventManager

__aexit__

  • async __aexit__(*, exc_type, exc_value, exc_traceback): None
  • Closes the local 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

    • optionalkeyword-onlyexc_type: type[BaseException] | None
    • optionalkeyword-onlyexc_value: BaseException | None
    • optionalkeyword-onlyexc_traceback: TracebackType | None

    Returns None

__init__

  • __init__(*, persist_state_interval, close_timeout): None
  • A default constructor.


    Parameters

    • optionalkeyword-onlypersist_state_interval: timedelta = timedelta(minutes=1)

      Interval between emitted PersistState events 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(*, event, event_data): None
  • Emit an event.


    Parameters

    • optionalkeyword-onlyevent: Event

      The event which will be emitted.

    • optionalkeyword-onlyevent_data: EventData

      The data which will be passed to the event listeners.

    Returns None

off

  • off(*, event, listener): None
  • Remove a listener, or all listeners, from an Actor event.


    Parameters

    • optionalkeyword-onlyevent: Event

      The Actor event for which to remove listeners.

    • optionalkeyword-onlylistener: Listener | None = None

      The listener which is supposed to be removed. If not passed, all listeners of this event are removed.

    Returns None

on

  • on(*, event, listener): None
  • Add an event listener to the event manager.


    Parameters

    • optionalkeyword-onlyevent: Event

      The Actor event for which to listen to.

    • optionalkeyword-onlylistener: Listener

      The function (sync or async) which is to be called when the event is emitted.

    Returns None

wait_for_all_listeners_to_complete

  • async wait_for_all_listeners_to_complete(*, timeout): None
  • 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

active: bool

Indicates whether the context is active.