Skip to content

AsyncTransactionalBackend

Bases: AsyncBackend

Async backend variant that provides transactional event handling support.

Note: in-transaction listeners remain synchronous callables even on async backends, as they are dispatched within the append transaction.

Source code in event_sourcery/_event_store/_async/backend.py
class AsyncTransactionalBackend(AsyncBackend):
    """
    Async backend variant that provides transactional event handling support.

    Note: in-transaction listeners remain synchronous callables even on async
    backends, as they are dispatched within the append transaction.
    """

    def __init__(self) -> None:
        super().__init__()
        self[Listeners] = singleton(lambda _: Listeners())
        self[AsyncDispatcher] = lambda c: AsyncDispatcher(
            AsyncBackend._serde_for(c),
            c[Listeners],
        )

    @property
    def in_transaction(self) -> Listeners:
        """
        Returns the current instance of `Listeners` for transactional event handling.
        """
        return cast(Listeners, self[Listeners])

in_transaction property

Returns the current instance of Listeners for transactional event handling.