Skip to main content

Events

Struct Events 

Source
pub struct Events { /* private fields */ }
Expand description

Server-wide event registry.

Owns the inline sinks and the deferred handlers. Sinks are awaited by post before it returns; handlers are queued and run one at a time on a single dispatcher task.

Implementations§

Source§

impl Events

Source

pub fn new() -> Self

Source

pub fn add_sink(&self, sink: Arc<dyn EventSink>)

Register an inline sink. Sinks are awaited in registration order.

May be called at any time, including from inside another sink’s call-out; the new sink takes effect from the next post.

Source

pub fn add_handler(&self, event: impl Into<String>, handler: EventHandler)

Register a deferred handler for event.

Handlers for one event run in registration order.

Source

pub fn dropped_count(&self) -> u64

Number of handler invocations dropped because the queue was full.

Source

pub fn failed_count(&self) -> u64

Number of sink or handler invocations that panicked.

Source

pub fn start_dispatcher(&self, store: Arc<SimplePvStore>)

Start the single dispatcher task. Call once, at server start.

Source

pub async fn post(&self, event: &str)

Post event: await every sink, then queue handlers and return.

Sinks run in registration order and are each wrapped in catch_unwind, exactly as handlers are on the dispatcher: a panicking sink is logged, counted in Self::failed_count, and the fan-out continues. Without that, one bad sink would unwind out of post and the remaining sinks and every handler would silently never see the event.

An unknown event name is a no-op — events are a dynamic namespace.

Source

pub async fn drain(&self)

Wait until every queued handler has finished. Test helper.

Bounded rather than an unconditional spin: this doubles as a deadlock detector. If a future change ever breaks the invariant that the dispatcher always decrements inflight (e.g. removing the catch_unwind around handler futures), a hung dispatcher must show up as a clear, named test failure — not an indefinitely hanging CI job.

Trait Implementations§

Source§

impl Default for Events

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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