[][src]Struct sqlx::postgres::PgListener

pub struct PgListener { /* fields omitted */ }
This is supported on crate feature postgres only.

A stream of asynchronous notifications from Postgres.

This listener will auto-reconnect. If the active connection being used ever dies, this listener will detect that event, create a new connection, will re-subscribe to all of the originally specified channels, and will resume operations as normal.

Implementations

impl PgListener[src]

pub async fn connect(uri: &'_ str) -> Result<PgListener, Error>[src]

This is supported on crate feature postgres only.

pub async fn connect_with(pool: &'_ Pool<Postgres>) -> Result<PgListener, Error>[src]

This is supported on crate feature postgres only.

pub async fn listen(&'_ mut self, channel: &'_ str) -> Result<(), Error>[src]

This is supported on crate feature postgres only.

Starts listening for notifications on a channel. The channel name is quoted here to ensure case sensitivity.

pub async fn listen_all<'_>(
    &'_ mut self,
    channels: impl IntoIterator<Item = &'_ str>
) -> Result<(), Error>
[src]

This is supported on crate feature postgres only.

Starts listening for notifications on all channels.

pub async fn unlisten(&'_ mut self, channel: &'_ str) -> Result<(), Error>[src]

This is supported on crate feature postgres only.

Stops listening for notifications on a channel. The channel name is quoted here to ensure case sensitivity.

pub async fn unlisten_all(&'_ mut self) -> Result<(), Error>[src]

This is supported on crate feature postgres only.

Stops listening for notifications on all channels.

pub async fn recv(&'_ mut self) -> Result<PgNotification, Error>[src]

This is supported on crate feature postgres only.

Receives the next notification available from any of the subscribed channels.

If the connection to PostgreSQL is lost, it is automatically reconnected on the next call to recv(), and should be entirely transparent (as long as it was just an intermittent network failure or long-lived connection reaper).

As notifications are transient, any received while the connection was lost, will not be returned. If you'd prefer the reconnection to be explicit and have a chance to do something before, please see try_recv.

Example

loop {
    // ask for next notification, re-connecting (transparently) if needed
    let notification = listener.recv().await?;

    // handle notification, do something interesting
}

pub async fn try_recv(&'_ mut self) -> Result<Option<PgNotification>, Error>[src]

This is supported on crate feature postgres only.

Receives the next notification available from any of the subscribed channels.

If the connection to PostgreSQL is lost, None is returned, and the connection is reconnected on the next call to try_recv().

Example

loop {
    // start handling notifications, connecting if needed
    while let Some(notification) = listener.try_recv().await? {
        // handle notification
    }

    // connection lost, do something interesting
}

pub fn into_stream(
    self
) -> impl Unpin + Stream<Item = Result<PgNotification, Error>>
[src]

This is supported on crate feature postgres only.

Consume this listener, returning a Stream of notifications.

The backing connection will be automatically reconnected should it be lost.

This has the same potential drawbacks as recv.

Trait Implementations

impl Debug for PgListener[src]

impl<'c> Executor<'c> for &'c mut PgListener[src]

type Database = Postgres

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,