pub struct NotifyChannel<T> { /* private fields */ }Expand description
Typed handle to a single PostgreSQL NOTIFY channel.
T is the JSON payload shape. Construct one per channel as a const-ish
value (name is &'static str) and reuse it everywhere that channel is
touched, so publish and subscribe sites can never disagree on the shape.
Implementations§
Source§impl<T> NotifyChannel<T>
impl<T> NotifyChannel<T>
Source§impl<T> NotifyChannel<T>where
T: Serialize,
impl<T> NotifyChannel<T>where
T: Serialize,
Sourcepub async fn publish<'e, E>(&self, executor: E, payload: &T) -> Result<()>where
E: PgExecutor<'e>,
pub async fn publish<'e, E>(&self, executor: E, payload: &T) -> Result<()>where
E: PgExecutor<'e>,
Publish payload on this channel.
Errors:
ForgeError::Serializationifserde_json::to_string(payload)fails.ForgeError::InvalidArgumentif the serialized payload exceedsMAX_PAYLOAD_BYTES. Use the change-log fallback for larger bodies.ForgeError::Databaseif the underlyingSELECT pg_notify(...)fails (transaction rolled back, connection dropped, etc.).
Source§impl<T> NotifyChannel<T>where
T: DeserializeOwned + Send + 'static,
impl<T> NotifyChannel<T>where
T: DeserializeOwned + Send + 'static,
Sourcepub async fn subscribe(
&self,
listener: PgListener,
) -> Result<impl Stream<Item = T>>
pub async fn subscribe( &self, listener: PgListener, ) -> Result<impl Stream<Item = T>>
Subscribe to this channel and return a stream of decoded payloads.
listener is consumed; the caller surrenders the connection to the
stream for the duration of the subscription. Notifications whose
payload fails JSON decoding are logged and skipped, so a malformed
publish from one peer cannot tear down a long-running subscriber.
Errors from the underlying recv (connection dropped, etc.) end the
stream; the caller decides whether to reconnect.
Auto Trait Implementations§
impl<T> Freeze for NotifyChannel<T>
impl<T> RefUnwindSafe for NotifyChannel<T>
impl<T> Send for NotifyChannel<T>
impl<T> Sync for NotifyChannel<T>
impl<T> Unpin for NotifyChannel<T>
impl<T> UnsafeUnpin for NotifyChannel<T>
impl<T> UnwindSafe for NotifyChannel<T>
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