pub struct Channel { /* private fields */ }Expand description
One WebSocket connection. Every segment of the channel is multiplexed over
it; another Channel, even for the same reference, is another connection
(SEG-01). Obtain one with Client::channel.
A Channel is cheap to clone, and every clone is the same channel. Close
it when done: dropping every handle also stops its connection, without the
closing handshake.
Implementations§
Source§impl Channel
impl Channel
Sourcepub fn state(&self) -> ChannelState
pub fn state(&self) -> ChannelState
The current state. It may change as soon as it is read.
Sourcepub fn events(&self) -> ChannelEventHandler
pub fn events(&self) -> ChannelEventHandler
The handler for channel-wide listeners.
Sourcepub fn segment(&self, segment_id: &str) -> Result<Segment, CelerisError>
pub fn segment(&self, segment_id: &str) -> Result<Segment, CelerisError>
A handle for the segment with the given id. It does no network work,
and any number of handles for one segment share its subscriptions and
listeners. It fails with CelerisError::Configuration for an id that
is empty or contains CR or LF.
Sourcepub fn default_segment(&self) -> Segment
pub fn default_segment(&self) -> Segment
A handle for the segment that every connection joins automatically (SEG-01).
Sourcepub async fn connect(&self) -> Result<(), CelerisError>
pub async fn connect(&self) -> Result<(), CelerisError>
Opens the connection. It returns once the WebSocket is established and the held subscriptions are queued to be restored ahead of any publish, or fails without a retry: only a connection that was up recovers automatically.
It fails with CelerisError::OperationInProgress while connecting,
connected or reconnecting, and with CelerisError::NotConnected once
the channel is closing or closed. A failed attempt leaves the channel
ChannelState::Failed, from which connect may be called again.
Dropping the returned future abandons the attempt and leaves the channel
failed.
Sourcepub async fn close(&self)
pub async fn close(&self)
Closes the connection and every segment handle with it. It is terminal
and idempotent, and returns within about five seconds even when the
server does not answer. Publishes and presence queries that still wait
fail with CelerisError::Cancelled.