pub struct AsyncEventEmitter<P: EventPublisher + 'static> { /* private fields */ }Expand description
Async event emitter for non-blocking event emission
This struct wraps an EventPublisher and provides fire-and-forget
emission semantics. Events are sent in background tasks using
tokio::spawn, ensuring they never block the caller.
Implementations§
Source§impl<P: EventPublisher + 'static> AsyncEventEmitter<P>
impl<P: EventPublisher + 'static> AsyncEventEmitter<P>
Sourcepub fn new(publisher: Arc<P>) -> Self
pub fn new(publisher: Arc<P>) -> Self
Create a new async event emitter
§Arguments
publisher- The event publisher to use for sending events
§Examples
use llm_memory_graph::observatory::{AsyncEventEmitter, InMemoryPublisher};
use std::sync::Arc;
let publisher = Arc::new(InMemoryPublisher::new());
let emitter = AsyncEventEmitter::new(publisher);Sourcepub fn new_silent(publisher: Arc<P>) -> Self
pub fn new_silent(publisher: Arc<P>) -> Self
Create a new async event emitter without error logging
Sourcepub fn emit(&self, event: MemoryGraphEvent)
pub fn emit(&self, event: MemoryGraphEvent)
Emit an event without blocking
This method spawns a background task to publish the event and returns immediately. Errors during emission are logged but don’t affect the caller.
§Arguments
event- The event to emit
§Examples
let publisher = Arc::new(InMemoryPublisher::new());
let emitter = AsyncEventEmitter::new(publisher);
let event = MemoryGraphEvent::QueryExecuted {
query_type: "test".to_string(),
results_count: 10,
duration_ms: 50,
timestamp: chrono::Utc::now(),
};
emitter.emit(event); // Returns immediatelySourcepub fn emit_batch(&self, events: Vec<MemoryGraphEvent>)
pub fn emit_batch(&self, events: Vec<MemoryGraphEvent>)
Sourcepub async fn emit_sync(&self, event: MemoryGraphEvent) -> Result<()>
pub async fn emit_sync(&self, event: MemoryGraphEvent) -> Result<()>
Sourcepub async fn stats(&self) -> EmissionStatsSnapshot
pub async fn stats(&self) -> EmissionStatsSnapshot
Sourcepub async fn reset_stats(&self)
pub async fn reset_stats(&self)
Reset all statistics to zero
Trait Implementations§
Source§impl<P: Clone + EventPublisher + 'static> Clone for AsyncEventEmitter<P>
impl<P: Clone + EventPublisher + 'static> Clone for AsyncEventEmitter<P>
Source§fn clone(&self) -> AsyncEventEmitter<P>
fn clone(&self) -> AsyncEventEmitter<P>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<P> Freeze for AsyncEventEmitter<P>
impl<P> !RefUnwindSafe for AsyncEventEmitter<P>
impl<P> Send for AsyncEventEmitter<P>
impl<P> Sync for AsyncEventEmitter<P>
impl<P> Unpin for AsyncEventEmitter<P>
impl<P> !UnwindSafe for AsyncEventEmitter<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