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 的別名