pub struct ListenerContext {
pub replaying: bool,
pub store: Option<Store>,
pub request: RequestContext,
/* private fields */
}Expand description
What a listener handler gets besides the event’s payload and meta (the ctx of
Listener::on).
Fields§
§replaying: boolThe event was committed before this connection began: a read model rebuilding from the start, and equally the backlog a reactor catches up on after a restart or a lost connection. A reactor must not skip side effects because of it (those events are new to it); submit with fixed command IDs instead, so they are safe to repeat. Use it to skip work that only matters live, e.g. a notification about something long past in a listener that starts at 0.
store: Option<Store>The listener’s store, if it has one (Listener::store).
request: RequestContextThe request context of the command that caused the event.
Implementations§
Source§impl ListenerContext
impl ListenerContext
Sourcepub fn follow(&self) -> RequestContext
pub fn follow(&self) -> RequestContext
A request context for commands caused by this event: same sender and correlation, this
event’s command as the cause, without an expected version or privileges. Pass it with
crate::Submit::context; ListenerContext::submit does.
Sourcepub async fn submit(&self, submit: Submit) -> Result<Vec<StoredEvent>, Error>
pub async fn submit(&self, submit: Submit) -> Result<Vec<StoredEvent>, Error>
Submits a command this event causes, on the listener’s connection, and returns its
events. It needs a fixed ID (Submit::id, e.g. confirm-<order>), so a redelivered
event runs it once; without one it is Error::Config. Unless the submit sets them,
the context is ListenerContext::follow and the tenant the event’s.
A rejection is Error::Rejected: returned from the handler (?), it parks the event
at once in a reactor (see Listener::park_after). Match it to accept one: match ctx.submit(s).await { Err(Error::Rejected(r)) if r.code == "unique_taken" => {} r => { r?; } }. Other errors as for Kernable::submit.
Sourcepub async fn query<T: DeserializeOwned>(&self, query: Query) -> Result<T, Error>
pub async fn query<T: DeserializeOwned>(&self, query: Query) -> Result<T, Error>
Asks a query on the listener’s connection, like Kernable::query; unless the query
sets it, for the event’s tenant. It is the listener’s own read: it keeps the
connection’s context, not the event’s sender.
Sourcepub async fn process_act(
&self,
name: &str,
context: RequestContext,
) -> Result<bool, Error>
pub async fn process_act( &self, name: &str, context: RequestContext, ) -> Result<bool, Error>
Sets as whom a business process acts, on the listener’s connection, like
Kernable::process_act: e.g. a reactor that gives each registered process an identity.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ListenerContext
impl !RefUnwindSafe for ListenerContext
impl !UnwindSafe for ListenerContext
impl Forget for ListenerContext
impl Move for ListenerContext
impl Send for ListenerContext
impl Sync for ListenerContext
impl Unpin for ListenerContext
impl UnsafeUnpin for ListenerContext
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request