pub struct Subscriber { /* private fields */ }
Expand description
A client that has entered pub/sub mode.
Once clients subscribe to a channel, they may only perform pub/sub related
commands. The Client
type is transitioned to a Subscriber
type in order
to prevent non-pub/sub methods from being called.
Implementations§
Source§impl Subscriber
impl Subscriber
Sourcepub fn get_subscribed(&self) -> &[String]
pub fn get_subscribed(&self) -> &[String]
Returns the set of channels currently subscribed to.
Sourcepub async fn next_message(&mut self) -> Result<Option<Message>>
pub async fn next_message(&mut self) -> Result<Option<Message>>
Receive the next message published on a subscribed channel, waiting if necessary.
None
indicates the subscription has been terminated.
Sourcepub fn into_stream(self) -> impl Stream<Item = Result<Message>>
pub fn into_stream(self) -> impl Stream<Item = Result<Message>>
Convert the subscriber into a Stream
yielding new messages published
on subscribed channels.
Subscriber
does not implement stream itself as doing so with safe code
is non trivial. The usage of async/await would require a manual Stream
implementation to use unsafe
code. Instead, a conversion function is
provided and the returned stream is implemented with the help of the
async-stream
crate.
Sourcepub async fn subscribe(&mut self, channels: &[String]) -> Result<()>
pub async fn subscribe(&mut self, channels: &[String]) -> Result<()>
Subscribe to a list of new channels
Sourcepub async fn unsubscribe(&mut self, channels: &[String]) -> Result<()>
pub async fn unsubscribe(&mut self, channels: &[String]) -> Result<()>
Unsubscribe to a list of new channels