Skip to main content

TransactionScope

Struct TransactionScope 

Source
pub struct TransactionScope<'a, P, C> { /* private fields */ }
Expand description

A live broker transaction, opened by Transactional::begin.

Publishes issued through the scope become visible together on commit, or not at all after abort; both consume the scope, so a double commit or a publish after settling is a compile error. This is the manual counterpart of the per-batch transaction the runtime drives for include_batch_publishing mounts.

The scope encodes values with the wrapper’s codec and sends them directly: the reply PublishTransform stack and the app-wide publish_layer middleware do not run here - both belong to the dispatch path, where a delivery context exists.

Dropping an unsettled scope logs a warning and leaves the broker transaction open (destructors cannot run async work); always settle explicitly.

Implementations§

Source§

impl<P, C> TransactionScope<'_, P, C>

Source

pub async fn publish<T: Serialize + Sync>( &mut self, name: &str, value: &T, ) -> Result<(), TransactionPublishError<P::Error>>

Encodes value with the wrapper’s codec and publishes it to name inside the transaction.

A failed publish does not settle the scope: the caller decides between retrying and abort. Aborting is the safe default - after an error the broker-side transaction state is implementation-defined.

§Errors

Returns TransactionPublishError::Encode when the codec rejects the value, and TransactionPublishError::Publish when the broker rejects the message.

§Cancel safety

As with Publisher::publish, cancel safety is broker-defined: dropping the future mid-flight may leave the message in an indeterminate state inside the transaction.

Source

pub async fn commit(self) -> Result<(), P::Error>

Commits the transaction: every publish issued through the scope becomes visible at once.

§Errors

Returns the publisher’s error when the broker rejects the commit. Per the TransactionalPublisher contract a failed commit closes the transaction, so the spent scope leaves the handle free for a fresh begin.

§Cancel safety

Not cancel-safe: dropping the future mid-commit leaves the broker transaction in an implementation-defined state. The scope treats itself as unsettled then - its drop warning fires - which is why open clears only after the broker call completes.

Source

pub async fn abort(self) -> Result<(), P::Error>

Aborts the transaction: nothing published through the scope becomes visible.

§Errors

Returns the publisher’s error when the broker fails to abort.

§Cancel safety

Not cancel-safe, exactly like commit: a future dropped mid-abort leaves the scope unsettled and its drop warning fires.

Trait Implementations§

Source§

impl<P, C> Debug for TransactionScope<'_, P, C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P, C> Drop for TransactionScope<'_, P, C>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'a, P, C> Freeze for TransactionScope<'a, P, C>

§

impl<'a, P, C> RefUnwindSafe for TransactionScope<'a, P, C>

§

impl<'a, P, C> Send for TransactionScope<'a, P, C>
where P: Sync, C: Sync,

§

impl<'a, P, C> Sync for TransactionScope<'a, P, C>
where P: Sync, C: Sync,

§

impl<'a, P, C> Unpin for TransactionScope<'a, P, C>

§

impl<'a, P, C> UnsafeUnpin for TransactionScope<'a, P, C>

§

impl<'a, P, C> UnwindSafe for TransactionScope<'a, P, C>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more