Skip to main content

sentinel_driver/connection/
notify_impl.rs

1use super::{notify, Connection, Notification, Result};
2
3impl Connection {
4    /// Subscribe to LISTEN/NOTIFY on a channel.
5    pub async fn listen(&mut self, channel: &str) -> Result<()> {
6        notify::listen(&mut self.conn, channel).await
7    }
8
9    /// Unsubscribe from a channel.
10    pub async fn unlisten(&mut self, channel: &str) -> Result<()> {
11        notify::unlisten(&mut self.conn, channel).await
12    }
13
14    /// Unsubscribe from all channels.
15    pub async fn unlisten_all(&mut self) -> Result<()> {
16        notify::unlisten_all(&mut self.conn).await
17    }
18
19    /// Send a notification on a channel.
20    pub async fn notify(&mut self, channel: &str, payload: &str) -> Result<()> {
21        notify::notify(&mut self.conn, channel, payload).await
22    }
23
24    /// Wait for the next LISTEN/NOTIFY notification.
25    ///
26    /// Blocks until a notification arrives on any subscribed channel.
27    pub async fn wait_for_notification(&mut self) -> Result<Notification> {
28        notify::wait_for_notification(&mut self.conn).await
29    }
30}