pub struct EventBus { /* private fields */ }Expand description
Registry of handlers, built once by Harness::build from every module’s
events(). Cheap to clone (two Arcs).
Implementations§
Source§impl EventBus
impl EventBus
Sourcepub fn on(self, name: impl Into<EventName>, handler: EventHandler) -> Self
pub fn on(self, name: impl Into<EventName>, handler: EventHandler) -> Self
Builds a bus from collected (name, handler) pairs, appending the
new pairs after any existing ones (copy-on-write if the bus is
already shared). Modules register via Module::events() at
Harness::build.
Sourcepub fn handlers(&self) -> &[(EventName, EventHandler)]
pub fn handlers(&self) -> &[(EventName, EventHandler)]
The registered (name, handler) pairs, in registration order.
Sourcepub fn deliver_inbound(
&self,
scope: &Scope,
name: &str,
payload: &Value,
) -> usize
pub fn deliver_inbound( &self, scope: &Scope, name: &str, payload: &Value, ) -> usize
The sidecar half of event forwarding (issue #62): the delivery the
host posted to POST /__events, run against this deployment’s own
handlers and this request’s defer. Returns the number of handlers
that subscribed, so the route can refuse to be silent about an
event nobody hears.
Sourcepub fn emit_in(&self, scope: &Scope, name: &str, payload: Value)
pub fn emit_in(&self, scope: &Scope, name: &str, payload: Value)
Runs every handler registered for name through the scope’s defer,
in the emitting request’s wait_until, and forwards the event to
every mounted sidecar (ADR 0017). Never fails the request; handler
errors are logged with the event name. An emission nothing heard —
no local handler and nothing forwarded — is warned about: the
silent delivery this issue was written to prevent.