events

class litestar.events.BaseEventEmitterBackend[源代码]

基类:AbstractAsyncContextManager[BaseEventEmitterBackend], ABC

Abstract class used to define event emitter backends.

__init__(listeners: Sequence[EventListener]) None[源代码]

Create an event emitter instance.

参数:

listeners -- A list of listeners.

abstractmethod emit(event_id: str, *args: Any, **kwargs: Any) None[源代码]

Emit an event to all attached listeners.

参数:
  • event_id -- The ID of the event to emit, e.g 'my_event'.

  • *args -- args to pass to the listener(s).

  • **kwargs -- kwargs to pass to the listener(s)

返回:

None

class litestar.events.EventListener[源代码]

基类:object

Decorator for event listeners

__call__(fn: AnyCallable) EventListener[源代码]

Decorate a callable by wrapping it inside an instance of EventListener.

参数:

fn -- Callable to decorate.

返回:

An instance of EventListener

__init__(*event_ids: str) None[源代码]

Create a decorator for event handlers.

参数:

*event_ids -- The id of the event to listen to or a list of event ids to listen to.

static wrap_in_error_handler(fn: AsyncAnyCallable) AsyncAnyCallable[源代码]

Wrap a listener function to handle errors.

Listeners are executed concurrently in a TaskGroup, so we need to ensure that exceptions do not propagate to the task group which results in any other unfinished listeners to be cancelled, and the receive stream to be closed.

See https://github.com/litestar-org/litestar/issues/2809

参数:

fn -- The listener function to wrap.

class litestar.events.SimpleEventEmitter[源代码]

基类:BaseEventEmitterBackend

Event emitter the works only in the current process

__init__(listeners: Sequence[EventListener]) None[源代码]

Create an event emitter instance.

参数:

listeners -- A list of listeners.

emit(event_id: str, *args: Any, **kwargs: Any) None[源代码]

Emit an event to all attached listeners.

参数:
  • event_id -- The ID of the event to emit, e.g 'my_event'.

  • *args -- args to pass to the listener(s).

  • **kwargs -- kwargs to pass to the listener(s)

返回:

None

litestar.events.listener

EventListener 的别名