Skip to content

AsyncSubscriptionStrategy

Interface for async event store backend subscription.

Async counterpart of SubscriptionStrategy. Defines the contract for subscribing to event streams in various ways, returning async iterators over batches of recorded events.

Source code in event_sourcery/_event_store/_async/subscription.py
class AsyncSubscriptionStrategy:
    """
    Interface for async event store backend subscription.

    Async counterpart of `SubscriptionStrategy`. Defines the contract for
    subscribing to event streams in various ways, returning async iterators
    over batches of recorded events.
    """

    def subscribe_to_all(
        self,
        start_from: Position,
        batch_size: int,
        timelimit: timedelta,
    ) -> AsyncIterator[list[RecordedRaw]]:
        """
        Subscribes to all events in the event store, starting from a given position.

        Args:
            start_from (Position): The position to start reading events from.
            batch_size (int): The maximum number of events to return in each batch.
            timelimit (timedelta): The maximum time to spend reading one batch.

        Returns:
            AsyncIterator[list[RecordedRaw]]:
                An async iterator over batches of recorded events.
        """
        raise NotImplementedError()

    def subscribe_to_category(
        self,
        start_from: Position,
        batch_size: int,
        timelimit: timedelta,
        category: str,
    ) -> AsyncIterator[list[RecordedRaw]]:
        """
        Subscribes to all events in a given category of streams, starting from a
        given position.

        Args:
            start_from (Position): The position to start reading events from.
            batch_size (int): The maximum number of events to return in each batch.
            timelimit (timedelta): The maximum time to spend reading one batch.
            category (str): The category of streams to subscribe to.

        Returns:
            AsyncIterator[list[RecordedRaw]]:
                An async iterator over batches of recorded events.
        """
        raise NotImplementedError()

    def subscribe_to_events(
        self,
        start_from: Position,
        batch_size: int,
        timelimit: timedelta,
        events: list[str],
    ) -> AsyncIterator[list[RecordedRaw]]:
        """
        Subscribes to all events of the given event types, starting from a position.

        Args:
            start_from (Position): The position to start reading events from.
            batch_size (int): The maximum number of events to return in each batch.
            timelimit (timedelta): The maximum time to spend reading one batch.
            events (list[str]): The list of event type names to subscribe to.

        Returns:
            AsyncIterator[list[RecordedRaw]]:
                An async iterator over batches of recorded events.
        """
        raise NotImplementedError()

subscribe_to_all(start_from, batch_size, timelimit)

Subscribes to all events in the event store, starting from a given position.

Parameters:

Name Type Description Default
start_from Position

The position to start reading events from.

required
batch_size int

The maximum number of events to return in each batch.

required
timelimit timedelta

The maximum time to spend reading one batch.

required

Returns:

Type Description
AsyncIterator[list[RecordedRaw]]

AsyncIterator[list[RecordedRaw]]: An async iterator over batches of recorded events.

Source code in event_sourcery/_event_store/_async/subscription.py
def subscribe_to_all(
    self,
    start_from: Position,
    batch_size: int,
    timelimit: timedelta,
) -> AsyncIterator[list[RecordedRaw]]:
    """
    Subscribes to all events in the event store, starting from a given position.

    Args:
        start_from (Position): The position to start reading events from.
        batch_size (int): The maximum number of events to return in each batch.
        timelimit (timedelta): The maximum time to spend reading one batch.

    Returns:
        AsyncIterator[list[RecordedRaw]]:
            An async iterator over batches of recorded events.
    """
    raise NotImplementedError()

subscribe_to_category(start_from, batch_size, timelimit, category)

Subscribes to all events in a given category of streams, starting from a given position.

Parameters:

Name Type Description Default
start_from Position

The position to start reading events from.

required
batch_size int

The maximum number of events to return in each batch.

required
timelimit timedelta

The maximum time to spend reading one batch.

required
category str

The category of streams to subscribe to.

required

Returns:

Type Description
AsyncIterator[list[RecordedRaw]]

AsyncIterator[list[RecordedRaw]]: An async iterator over batches of recorded events.

Source code in event_sourcery/_event_store/_async/subscription.py
def subscribe_to_category(
    self,
    start_from: Position,
    batch_size: int,
    timelimit: timedelta,
    category: str,
) -> AsyncIterator[list[RecordedRaw]]:
    """
    Subscribes to all events in a given category of streams, starting from a
    given position.

    Args:
        start_from (Position): The position to start reading events from.
        batch_size (int): The maximum number of events to return in each batch.
        timelimit (timedelta): The maximum time to spend reading one batch.
        category (str): The category of streams to subscribe to.

    Returns:
        AsyncIterator[list[RecordedRaw]]:
            An async iterator over batches of recorded events.
    """
    raise NotImplementedError()

subscribe_to_events(start_from, batch_size, timelimit, events)

Subscribes to all events of the given event types, starting from a position.

Parameters:

Name Type Description Default
start_from Position

The position to start reading events from.

required
batch_size int

The maximum number of events to return in each batch.

required
timelimit timedelta

The maximum time to spend reading one batch.

required
events list[str]

The list of event type names to subscribe to.

required

Returns:

Type Description
AsyncIterator[list[RecordedRaw]]

AsyncIterator[list[RecordedRaw]]: An async iterator over batches of recorded events.

Source code in event_sourcery/_event_store/_async/subscription.py
def subscribe_to_events(
    self,
    start_from: Position,
    batch_size: int,
    timelimit: timedelta,
    events: list[str],
) -> AsyncIterator[list[RecordedRaw]]:
    """
    Subscribes to all events of the given event types, starting from a position.

    Args:
        start_from (Position): The position to start reading events from.
        batch_size (int): The maximum number of events to return in each batch.
        timelimit (timedelta): The maximum time to spend reading one batch.
        events (list[str]): The list of event type names to subscribe to.

    Returns:
        AsyncIterator[list[RecordedRaw]]:
            An async iterator over batches of recorded events.
    """
    raise NotImplementedError()