pub struct DogEventHub<R, P>{ /* private fields */ }Expand description
Minimal runtime-agnostic event hub.
IMPORTANT DESIGN:
- We do NOT want callers to need
&mut DogEventHubjust to emit, because DogApp holds this behind anRwLock. - We also do NOT want to hold a lock across
.await.
So we split emission into:
- snapshot (read-only, no await)
- await listeners (no lock held)
- cleanup once-listeners (write-lock, no await)
Implementations§
Source§impl<R, P> DogEventHub<R, P>
impl<R, P> DogEventHub<R, P>
pub fn new() -> Self
pub fn set_publish(&mut self, f: PublishFn<R, P>)
pub fn clear_publish(&mut self)
Sourcepub fn on_exact(
&mut self,
path: impl Into<String>,
event: ServiceEventKind,
listener: EventListener<R, P>,
) -> ListenerId
pub fn on_exact( &mut self, path: impl Into<String>, event: ServiceEventKind, listener: EventListener<R, P>, ) -> ListenerId
Exact: app.on(“messages”, Created, …)
Sourcepub fn on_pattern(
&mut self,
pattern: ServiceEventPattern,
listener: EventListener<R, P>,
) -> ListenerId
pub fn on_pattern( &mut self, pattern: ServiceEventPattern, listener: EventListener<R, P>, ) -> ListenerId
Sugar: app.on_str(“messages.created”, …)
Sourcepub fn once_pattern(
&mut self,
pattern: ServiceEventPattern,
listener: EventListener<R, P>,
) -> ListenerId
pub fn once_pattern( &mut self, pattern: ServiceEventPattern, listener: EventListener<R, P>, ) -> ListenerId
Feathers-ish: once(…)
Sourcepub fn off(&mut self, id: ListenerId) -> bool
pub fn off(&mut self, id: ListenerId) -> bool
removeListener/off
Sourcepub fn remove_all(&mut self, pattern: Option<&ServiceEventPattern>) -> usize
pub fn remove_all(&mut self, pattern: Option<&ServiceEventPattern>) -> usize
removeAllListeners (optionally scoped)
Sourcepub fn snapshot_emit<'a>(
&'a self,
path: &str,
event: &ServiceEventKind,
data: &ServiceEventData<'a, R>,
ctx: &HookContext<R, P>,
) -> (Vec<EventListener<R, P>>, Vec<ListenerId>)
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.
Sourcepub fn finalize_once_removals(&mut self, once_ids: &[ListenerId])
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.
Sourcepub async fn emit_async(
&mut self,
path: &str,
event: &ServiceEventKind,
data: &ServiceEventData<'_, R>,
ctx: &HookContext<R, P>,
) -> Result<()>
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§
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> 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
Mutably borrows from an owned value. Read more