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 three entry verbs.

§Presence contract

A singleton subscriber is always on, and that presence is what licenses its ephemeral subscription: ephemeral events cannot be replayed, so only an always-present consumer may hear them. This ctx therefore has no pausing verb — no pause_until, no staged chain. Their absence is semantic, not an omission: a verb that suspends consumption would contradict the property that defines the mode.

use obix::{EventCtx, Handled};

fn pause_it<'inv>(ctx: EventCtx<'inv>) -> Handled<'inv> {
    // error[E0599]: no method named `pause_until` found for struct `EventCtx`
    //
    // A flow that pauses or stages is persistent-only by definition —
    // host it as a keyed subscriber; a single static key is legitimate.
    ctx.pause_until()
}

The control for the negative test above — same signature, with a verb a singleton ctx does have. If this stops compiling, the compile_fail above has started passing for the wrong reason:

use obix::{EventCtx, Handled};

fn resolve_it<'inv>(ctx: EventCtx<'inv>) -> Handled<'inv> {
    ctx.skip()
}

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.

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( self, ) -> Result<IsolatedOp<'inv>, Box<dyn Error + Send + Sync>>
where B: Default,

Land the pending batch first (its collected items 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.

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>
where &'inv mut B: Freeze, &'inv dyn ItemFlush<B>: Freeze,

§

impl<'inv, B> Send for EventCtx<'inv, B>
where &'inv mut B: Send, &'inv dyn ItemFlush<B>: Send,

§

impl<'inv, B> Unpin for EventCtx<'inv, B>
where &'inv mut B: Unpin, &'inv dyn ItemFlush<B>: Unpin,

§

impl<'inv, B> UnsafeUnpin for EventCtx<'inv, B>
where &'inv mut B: UnsafeUnpin, &'inv dyn ItemFlush<B>: UnsafeUnpin,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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