pub struct ChannelListener { /* private fields */ }Expand description
A live subscription to one Channel, returned by crate::Client::listen.
Holds a dedicated (non-pooled) connection for as long as it’s alive —
LISTEN is per-session, so sharing a pooled connection would leak the
subscription onto whatever unrelated query later borrows that same
connection back out of the pool. Dropping this closes the connection
and ends the server-side subscription with it.
Implementations§
Source§impl ChannelListener
impl ChannelListener
Sourcepub async fn recv(&mut self) -> Option<Result<Value>>
pub async fn recv(&mut self) -> Option<Result<Value>>
Waits for the next decoded payload. Returns None once the dedicated
connection closes, or once a payload has failed to decode.
A malformed payload yields Err(Error::MalformedPayload(_)) and
ends the subscription — every later call returns None. A channel
is a database-wide name, so anything can publish to it; failing hard
keeps foreign data on a typed channel visible instead of silently
dropped, and not resuming keeps that failure from being papered over
by the next good message.
A consumer that needs to stay subscribed past a bad message re-subscribes itself:
loop {
let mut sub = client.listen("UserUpdates").await?;
while let Some(payload) = sub.recv().await {
match payload {
Ok(v) => handle(v),
Err(e) => { log(e); break; } // re-listen on the next pass
}
}
}This matches Client.listen() on the Python side, where the same
failure raises out of the async for and ends the generator.
Auto Trait Implementations§
impl !RefUnwindSafe for ChannelListener
impl !UnwindSafe for ChannelListener
impl Freeze for ChannelListener
impl Send for ChannelListener
impl Sync for ChannelListener
impl Unpin for ChannelListener
impl UnsafeUnpin for ChannelListener
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.