Skip to main content

Crate larust_events

Crate larust_events 

Source
Expand description

A lightweight, explicit, in-process pub/sub - Laravel’s Event::dispatch/ listeners, deliberately scaled down. No persistence, no queue involvement, no derive macro, no DI-container resolution: listeners are registered explicitly (listeners().on::<E>(...), same “build a registry, then publish it” shape as larust_http::route’s named-route registry), and every listener for an event runs synchronously, in registration order, in-process - the same default Laravel itself uses (only a ShouldQueue listener defers there). A listener that needs to defer real work should enqueue a larust_queue::Job instead of doing it inline.

Structs§

ListenerRegistry

Traits§

Event
Any plain Clone + Send + Sync + 'static value can be an event - a blanket impl, no derive, no required methods. Clone is required because each of possibly-several listeners for one dispatch gets its own owned copy to move into its independently-'static future.

Functions§

dispatch
Runs every listener registered for E, sequentially, awaiting each in turn before moving to the next. A silent no-op if listeners()... publish() was never called, or if nothing is registered for this specific E - there’s no failure mode here worth an AppError; a listener that can fail should log its own error internally rather than short-circuit the others.
listeners
Starts building the process-wide listener registry. Call .on::<E>(...) for each listener, then .publish() once, typically right before Application::serve().