pub struct PgNotifyBus { /* private fields */ }Expand description
Implementations§
Source§impl PgNotifyBus
impl PgNotifyBus
Sourcepub fn new(pool: PgPool, channels: &[&str]) -> Self
pub fn new(pool: PgPool, channels: &[&str]) -> Self
Create a new notify bus for the given channels.
Each channel gets a broadcast::channel(256) so subscribers can lag
slightly without losing messages. The bus does not start listening
until run is called.
Sourcepub fn subscribe(&self, channel: &str) -> Option<Receiver<String>>
pub fn subscribe(&self, channel: &str) -> Option<Receiver<String>>
Subscribe to notifications on channel.
Returns None if channel was not registered at construction time.
The returned receiver yields the raw NOTIFY payload string.
Sourcepub fn channels(&self) -> Vec<&str>
pub fn channels(&self) -> Vec<&str>
Returns the set of channel names this bus is configured for.
Sourcepub fn subscribe_reconnects(&self) -> Receiver<u64>
pub fn subscribe_reconnects(&self) -> Receiver<u64>
Subscribe to reconnect events.
The returned receiver’s value is bumped once per successful (re)connect
of the underlying PgListener. The initial connect publishes 1;
subsequent reconnects publish 2, 3, etc. Subscribers that want to
trigger gap recovery on reconnect should:
- Call
subscribe_reconnects()and snapshot the current generation via*rx.borrow(). - In their main loop,
select!onrx.changed()alongside their payloadrecv(). - On a change, compare
*rx.borrow()to the snapshot and only treat it as a reconnect if it is strictly greater than the snapshot — this filters the first-boot connect for subscribers that attach beforerun()succeeds.
Auto Trait Implementations§
impl Freeze for PgNotifyBus
impl !RefUnwindSafe for PgNotifyBus
impl Send for PgNotifyBus
impl Sync for PgNotifyBus
impl Unpin for PgNotifyBus
impl UnsafeUnpin for PgNotifyBus
impl !UnwindSafe for PgNotifyBus
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more