pub struct Subscription<S> { /* private fields */ }Expand description
A live server-push subscription stream. Drain events with Self::next;
call Self::unsubscribe for a clean teardown (the server then EOS-closes
the event stream, which next observes as end-of-stream).
Dropping a subscription deregisters its route so a forgotten handle doesn’t
leak an entry in the route table — but Drop can’t send UNSUBSCRIBE (it
isn’t async), so a dropped-without-unsubscribe subscription leaves the
server pushing into a now-dead channel until it notices. Prefer
unsubscribe().await before dropping.
Implementations§
Source§impl<S> Subscription<S>where
S: AsyncWrite,
impl<S> Subscription<S>where
S: AsyncWrite,
Sourcepub fn stream_id(&self) -> u32
pub fn stream_id(&self) -> u32
The stream id the server pushes events on. Pass it to the server’s UNSUBSCRIBE target if driving the protocol manually.
Sourcepub async fn next(&mut self) -> Option<Result<SubscriptionEvent>>
pub async fn next(&mut self) -> Option<Result<SubscriptionEvent>>
Await the next subscription event. Returns Some(Ok(event)) for each
pushed SUBSCRIBE_EVENT, Some(Err(_)) if a frame failed to decode or
the server sent an ERROR on the stream, and None once the stream has
ended (the server EOS-closed it, or the connection dropped).
An EOS-flagged frame carrying an event yields that event; the following
call returns None. An EOS frame with an empty payload ends the stream
immediately.
Sourcepub async fn unsubscribe(&self) -> Result<UnsubscribeResponse>
pub async fn unsubscribe(&self) -> Result<UnsubscribeResponse>
Tear the subscription down cleanly: send UNSUBSCRIBE on a fresh stream
and await its UNSUBSCRIBE_RESP. The server then EOS-closes the event
stream, which a subsequent Self::next observes as None.