Skip to main content

DogEventHub

Struct DogEventHub 

Source
pub struct DogEventHub<R, P>
where R: Send + 'static, P: Send + Clone + 'static,
{ /* private fields */ }
Expand description

Minimal runtime-agnostic event hub.

IMPORTANT DESIGN:

  • We do NOT want callers to need &mut DogEventHub just to emit, because DogApp holds this behind an RwLock.
  • We also do NOT want to hold a lock across .await.

So we split emission into:

  1. snapshot (read-only, no await)
  2. await listeners (no lock held)
  3. cleanup once-listeners (write-lock, no await)

Implementations§

Source§

impl<R, P> DogEventHub<R, P>
where R: Send + 'static, P: Send + Clone + 'static,

Source

pub fn new() -> Self

Source

pub fn set_publish(&mut self, f: PublishFn<R, P>)

Source

pub fn clear_publish(&mut self)

Source

pub fn on_exact( &mut self, path: impl Into<String>, event: ServiceEventKind, listener: EventListener<R, P>, ) -> ListenerId

Exact: app.on(“messages”, Created, …)

Source

pub fn on_pattern( &mut self, pattern: ServiceEventPattern, listener: EventListener<R, P>, ) -> ListenerId

Sugar: app.on_str(“messages.created”, …)

Source

pub fn once_pattern( &mut self, pattern: ServiceEventPattern, listener: EventListener<R, P>, ) -> ListenerId

Feathers-ish: once(…)

Source

pub fn off(&mut self, id: ListenerId) -> bool

removeListener/off

Source

pub fn remove_all(&mut self, pattern: Option<&ServiceEventPattern>) -> usize

removeAllListeners (optionally scoped)

Source

pub fn snapshot_emit<'a>( &'a self, path: &str, event: &ServiceEventKind, data: &ServiceEventData<'a, R>, ctx: &HookContext<R, P>, ) -> (Vec<EventListener<R, P>>, Vec<ListenerId>)

Phase 1: snapshot matching listeners + remember which once listener ids to remove.

NOTE: no .await here, so it’s safe under a read-lock.

Source

pub fn finalize_once_removals(&mut self, once_ids: &[ListenerId])

Phase 3: remove once listeners after emit finishes.

NOTE: no .await, safe under a write-lock.

Source

pub async fn emit_async( &mut self, path: &str, event: &ServiceEventKind, data: &ServiceEventData<'_, R>, ctx: &HookContext<R, P>, ) -> Result<()>

Optional convenience if you ever hold &mut self directly (tests, single-thread use, etc.) This keeps the original API, but it is NOT required by DogApp anymore.

Trait Implementations§

Source§

impl<R, P> Default for DogEventHub<R, P>
where R: Send + 'static, P: Send + Clone + 'static,

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<R, P> Freeze for DogEventHub<R, P>

§

impl<R, P> !RefUnwindSafe for DogEventHub<R, P>

§

impl<R, P> Send for DogEventHub<R, P>

§

impl<R, P> Sync for DogEventHub<R, P>

§

impl<R, P> Unpin for DogEventHub<R, P>

§

impl<R, P> !UnwindSafe for DogEventHub<R, P>

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