Skip to content

AsyncSubscription

Asynchronous context manager for a long-lived Herdr event stream. It is normally created with AsyncHerdrClient.subscribe.

Constructor

Prepare an asynchronous subscription without opening the socket.

Parameters:

Name Type Description Default
socket_path Path

Unix socket path used for the subscription connection.

required
timeout float

Timeout in seconds for connect, write and read operations.

required
subscriptions Iterable[EventSubscription]

Event filters sent to events.subscribe when the context is entered.

required
Example
subscription = AsyncSubscription(
    Path("/tmp/herdr.sock"),
    timeout=5.0,
    subscriptions=[{"event": "pane.output"}],
)
Source code in src/herdr_client/async_client/client.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
def __init__(
    self,
    socket_path: Path,
    timeout: float,
    subscriptions: Iterable[EventSubscription],
) -> None:
    """Prepare an asynchronous subscription without opening the socket.

    Args:
        socket_path: Unix socket path used for the subscription connection.
        timeout: Timeout in seconds for connect, write and read operations.
        subscriptions: Event filters sent to ``events.subscribe`` when the
            context is entered.

    Example:
        ```python
        subscription = AsyncSubscription(
            Path("/tmp/herdr.sock"),
            timeout=5.0,
            subscriptions=[{"event": "pane.output"}],
        )
        ```
    """
    self._socket_path = socket_path
    self._timeout = timeout
    self._subscriptions = list(subscriptions)
    self._reader: asyncio.StreamReader | None = None
    self._writer: asyncio.StreamWriter | None = None
    self._ack: SubscriptionAck | None = None
Member Purpose
ack Read the server acknowledgement
__aenter__ Open the async context
__aexit__ Close the async context
aclose Close the connection explicitly
events Iterate asynchronously over events