# tmux_stream

- **Package:** libtmux_erlang
- **Language:** Erlang
- **Kind:** module
- **Source:** https://github.com/libtmux/libtmux-erlang/blob/38478dff54579a4f408005d0265031abdf3a880a/apps/libtmux_erlang/src/tmux_stream.erl#L1
- **Page:** https://libtmux.org/en/erlang/latest/reference/tmux_stream/

Subscribe to pane bytes and notifications on a dedicated tmux control client.

Each subscription belongs to its creating process. Share a subscription so
another process can join the client with its own credit. If the first
subscriber's process exits, the client retires.

Messages have the form `{tmux_stream, Subscription, Message}`. An event
contains its generation, sequence and native data. A gap reports unknown
loss after the last delivered sequence and retires that subscription. Use a
new subscription to observe subsequent output and `tmux_pane:capture/2`
to read the rendered screen.

## Members

### Common operations

- [`subscribe/3`](/en/erlang/latest/reference/tmux_stream-subscribe-3/) (function): Start a dedicated client on an owned or borrowed server and subscribe this process. Pass a session captured on that endpoint. Attaching skips the session environment update and ignores the client's size. Native hooks still run. The client retires when tmux reports a different session. The returned subscription includes its initial credit. Start effects after this call returns to observe their output. A startup error can return a control handle for `tmux_control:close/1` when native retirement needs another attempt.
- [`ack/3`](/en/erlang/latest/reference/tmux_stream-ack-3/) (function): Acknowledge one delivered sequence in its generation. Duplicate acknowledgements are idempotent. Returned capacity can be requested again with `demand/2`.
- [`demand/2`](/en/erlang/latest/reference/tmux_stream-demand-2/) (function): Add credit for future deliveries. Unused credit plus delivered data awaiting acknowledgement must fit within 64 KiB and eight messages. An `await_timeout` leaves the credit change unconfirmed.
- [`join/2`](/en/erlang/latest/reference/tmux_stream-join-2/) (function): Subscribe this process to the same dedicated client as an active subscription. The new subscription has its own credit and sequence numbers. It starts receiving data when it joins.

### Other members

- [`close/1`](/en/erlang/latest/reference/tmux_stream-close-1/) (function): Close this subscription. Closing the final subscription waits for confirmed retirement of its control client. A cleanup error leaves retirement running and permits another close attempt.
- [`credit/0`](/en/erlang/latest/reference/t-tmux_stream-credit-0/) (typealias): Bytes cover the event's binary fields. Messages count events.
- [`event/0`](/en/erlang/latest/reference/t-tmux_stream-event-0/) (typealias): Raw pane bytes or a native notification name and its unparsed fields.
- [`message/0`](/en/erlang/latest/reference/t-tmux_stream-message-0/) (typealias): Messages delivered to the subscriber's mailbox.
- [`options/0`](/en/erlang/latest/reference/t-tmux_stream-options-0/) (typealias): Initial credit defaults to 64 KiB and eight messages.
- [`subscription/0`](/en/erlang/latest/reference/t-tmux_stream-subscription-0/) (typealias): One subscription on a dedicated control client.

## Guides

Pages that discuss `tmux_stream`.

- [Native API documentation](/en/erlang/latest/guides/api-documentation/)
