pub struct EventStream { /* private fields */ }Expand description
Event stream with broadcast capability for real-time subscribers
Implementations§
Source§impl EventStream
impl EventStream
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create event stream with custom channel capacity
Sourcepub fn append(
&self,
event_type: EventType,
workflow_id: WorkflowId,
data: JsonValue,
) -> JoinHandle<Event>
pub fn append( &self, event_type: EventType, workflow_id: WorkflowId, data: JsonValue, ) -> JoinHandle<Event>
Append a new event and broadcast to all subscribers
Events are emitted asynchronously in a spawned task to avoid blocking agent execution. Returns a JoinHandle that can be awaited if the caller needs to ensure the event was processed or needs the Event object.
§Examples
use agent_runtime::event::{EventStream, EventType};
use serde_json::json;
let stream = EventStream::new();
// Fire and forget (most common)
stream.append(EventType::AgentInitialized, "workflow_1".to_string(), json!({}));
// Wait for event if needed
let event = stream.append(EventType::AgentCompleted, "workflow_1".to_string(), json!({}))
.await
.unwrap();Sourcepub fn append_with_parent(
&self,
event_type: EventType,
workflow_id: WorkflowId,
parent_workflow_id: Option<WorkflowId>,
data: JsonValue,
) -> JoinHandle<Event>
pub fn append_with_parent( &self, event_type: EventType, workflow_id: WorkflowId, parent_workflow_id: Option<WorkflowId>, data: JsonValue, ) -> JoinHandle<Event>
Append event with optional parent workflow ID
Events are emitted asynchronously to avoid blocking execution. Returns a JoinHandle that resolves to the created Event.
Sourcepub fn subscribe(&self) -> Receiver<Event>
pub fn subscribe(&self) -> Receiver<Event>
Subscribe to real-time event stream Returns a receiver that will get all future events
Sourcepub fn from_offset(&self, offset: EventOffset) -> Vec<Event>
pub fn from_offset(&self, offset: EventOffset) -> Vec<Event>
Get events from a specific offset (for replay)
pub fn is_empty(&self) -> bool
Sourcepub fn current_offset(&self) -> EventOffset
pub fn current_offset(&self) -> EventOffset
Get the current offset (next event will have this offset)
Trait Implementations§
Source§impl Clone for EventStream
impl Clone for EventStream
Auto Trait Implementations§
impl Freeze for EventStream
impl !RefUnwindSafe for EventStream
impl Send for EventStream
impl Sync for EventStream
impl Unpin for EventStream
impl !UnwindSafe for EventStream
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