Skip to main content

EventCtx

Struct EventCtx 

Source
pub struct EventCtx<'inv, B = ()> { /* private fields */ }
Expand description

Per-event decision point handed to handle_persistent.

Generic over the handler’s Batch accumulator B (defaulting to () for handlers that never collect). See the module docs for the semantics of the four entry verbs.

Implementations§

Source§

impl<'inv, B> EventCtx<'inv, B>

Source

pub fn skip(self) -> Handled<'inv>

This event is not for me — no transaction is opened, an open batch op is left untouched, and the checkpoint advances lazily (piggybacked on the next flush, or persisted on the configured checkpoint interval).

Source

pub fn collect_with(self, f: impl FnOnce(&mut B)) -> Handled<'inv>

Contribute to the pending batch’s accumulator — a pure memory write: no transaction is opened and no statement is executed now. The runner hands the accumulated batch to the handler’s flush exactly once per batch landing, inside the transaction that commits the checkpoint.

Like defer, collected work shares fate with its neighbors and must tolerate whole-batch replay: on a failed flush the events replay and their items are re-collected.

For Vec and HashMap accumulators the collect sugar is usually more convenient.

Source

pub async fn consume_in_batch( self, ) -> Result<BatchOp<'inv>, Box<dyn Error + Send + Sync>>

Do transactional work joined to the pending batch op (opening a fresh one if none is pending).

Work in a batch shares fate with its neighbors: a failure anywhere in the batch rolls back and replays the whole batch from the last committed checkpoint. Only choose this when the handler’s work is idempotent under such replay (pure in-op DB writes and in-op job spawns are — they roll back with the op).

Source

pub async fn consume_isolated( self, ) -> Result<IsolatedOp<'inv>, Box<dyn Error + Send + Sync>>
where B: Default,

Land the pending batch first (its collected items, its work and its checkpoint, at the last fully handled sequence), then hand back a fresh op: this event is its own atomic unit, sharing no fate with history — and none with the future either, since IsolatedOp only offers commit.

This is the failure-isolation fence: if this event’s work fails, only this event replays; and it is the exact legacy per-event semantics when no batch is pending.

Source§

impl<'inv, T> EventCtx<'inv, Vec<T>>

Source

pub fn collect(self, item: T) -> Handled<'inv>

collect_with sugar for Vec accumulators: append one item to the pending batch.

Source§

impl<'inv, K, V, S> EventCtx<'inv, HashMap<K, V, S>>
where K: Hash + Eq, S: BuildHasher,

Source

pub fn collect(self, key: K, value: V) -> Handled<'inv>

collect_with sugar for HashMap accumulators: keyed last-write-wins insert. Persistent events arrive in ascending sequence, so within a batch this naturally keeps the newest item per key — the coalescing fold (N updates per key → 1 flushed entry).

Auto Trait Implementations§

§

impl<'inv, B = ()> !RefUnwindSafe for EventCtx<'inv, B>

§

impl<'inv, B = ()> !Sync for EventCtx<'inv, B>

§

impl<'inv, B = ()> !UnwindSafe for EventCtx<'inv, B>

§

impl<'inv, B> Freeze for EventCtx<'inv, B>

§

impl<'inv, B> Send for EventCtx<'inv, B>
where B: Send,

§

impl<'inv, B> Unpin for EventCtx<'inv, B>

§

impl<'inv, B> UnsafeUnpin for EventCtx<'inv, B>

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> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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