pub struct EventBus { /* private fields */ }Expand description
The serial event dispatcher.
Implementations§
Source§impl EventBus
impl EventBus
Sourcepub fn new(rx: Receiver<Event>) -> Self
pub fn new(rx: Receiver<Event>) -> Self
Build a new bus from an mpsc receiver. The paired Sender must be
held by callers (and shared to sources) so they can push events.
Sourcepub fn on(
&mut self,
kind: impl Into<String>,
handler: HandlerKey,
) -> Result<(), BlockError>
pub fn on( &mut self, kind: impl Into<String>, handler: HandlerKey, ) -> Result<(), BlockError>
Register a kind-specific handler. Last write wins — re-registering
the same kind silently replaces the previous handler (documented
in plan.md §Phase 3 / wf-sim Counter-WF).
Returns Err(BlockError::Bus) if called after EventBus::run has
begun.
Sourcepub fn on_any(&mut self, handler: HandlerKey) -> Result<(), BlockError>
pub fn on_any(&mut self, handler: HandlerKey) -> Result<(), BlockError>
Register the on_any fallback. Invoked only when no on(kind)
handler matches the event’s kind. NOT a fan-out/tap.
Sourcepub async fn run(
&mut self,
shutdown: CancellationToken,
) -> Result<(), BlockError>
pub async fn run( &mut self, shutdown: CancellationToken, ) -> Result<(), BlockError>
Drive the dispatcher loop until shutdown is cancelled.
Cancel-safety: mpsc::Receiver::recv is cancel-safe; dropping the
select! branch on the recv side loses no events (tokio docs).
CancellationToken::cancelled is explicitly designed for this
usage (tokio-util docs).
Auto Trait Implementations§
impl !RefUnwindSafe for EventBus
impl !UnwindSafe for EventBus
impl Freeze for EventBus
impl Send for EventBus
impl Sync for EventBus
impl Unpin for EventBus
impl UnsafeUnpin for EventBus
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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