pub struct Topic<T> { /* private fields */ }Expand description
One topic under one key. Cheap to build; hold none. subscribe and
channel are the [TopicHandle]’s; publish is this type’s own, so a
topic bound to an @isolation attempt rides it.
Implementations§
Source§impl<T> Topic<T>
impl<T> Topic<T>
Sourcepub fn new(
backplane: Arc<dyn SubscriptionBackplane>,
topic: &str,
key: impl Display,
) -> Self
pub fn new( backplane: Arc<dyn SubscriptionBackplane>, topic: &str, key: impl Display, ) -> Self
topic is the declared name (RoomMessage), key the key’s value.
Sourcepub async fn publish(&self, message: &T) -> Result<(), CratestackError>
pub async fn publish(&self, message: &T) -> Result<(), CratestackError>
Delivers message to every current subscriber, on every replica.
From an @isolation procedure’s handle it is delivered only if the
attempt commits, never for one that rolls back or retries: with
PgNotifyBackplane as Self::publish_in_tx in a savepoint of the
attempt, with any other backplane queued and sent after the commit.
Inside db.transaction(..) there, use publish_in_tx(tx, ..).
Sourcepub async fn publish_in_tx(
&self,
tx: &mut Transaction<'_, Postgres>,
message: &T,
) -> Result<(), CratestackError>
pub async fn publish_in_tx( &self, tx: &mut Transaction<'_, Postgres>, message: &T, ) -> Result<(), CratestackError>
Delivers message only if tx commits, when it commits. On a topic
from an @isolation procedure’s handle, a backplane the transaction
cannot notify gets it queued until the attempt commits (dropped if
this db.transaction(..) rolls back). Otherwise such a backplane
(InProcessBackplane) is refused: call Self::publish after the
commit instead.
Methods from Deref<Target = TopicHandle<T>>§
pub fn encode(&self, message: &T) -> Result<String, CratestackError>
pub fn encode(&self, message: &T) -> Result<String, CratestackError>
message as the JSON payload the backplane carries.
pub async fn publish(&self, message: &T) -> Result<(), CratestackError>
pub async fn publish(&self, message: &T) -> Result<(), CratestackError>
Delivers message to every current subscriber, on every replica.
pub async fn subscribe(
&self,
) -> Result<Pin<Box<dyn Stream<Item = Result<T, CratestackError>> + Send>>, CratestackError>
pub async fn subscribe( &self, ) -> Result<Pin<Box<dyn Stream<Item = Result<T, CratestackError>> + Send>>, CratestackError>
Every message published from now on. Resolves once the subscription
is live. Ends with unavailable when it falls behind
("subscription lagged") or the backplane may have lost messages
("subscription interrupted"): resubscribe and refetch.
Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for Topic<T>
impl<T> !UnwindSafe for Topic<T>
impl<T> Freeze for Topic<T>
impl<T> Send for Topic<T>
impl<T> Sync for Topic<T>
impl<T> Unpin for Topic<T>
impl<T> UnsafeUnpin for Topic<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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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> ⓘ
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> ⓘ
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