Skip to main content

EventSink

Trait EventSink 

Source
pub trait EventSink:
    Send
    + Sync
    + 'static {
    // Required methods
    fn send(&self, event: UiMessage) -> Result<(), SendError>;
    fn clone_box(&self) -> Box<dyn EventSink>;

    // Provided method
    fn send_async(
        &self,
        event: UiMessage,
    ) -> Pin<Box<dyn Future<Output = Result<(), SendError>> + Send + '_>> { ... }
}
Expand description

Receives events from the agent engine and delivers them to a consumer.

Implementations handle the transport-specific details of delivering events to the user interface (TUI, WebSocket, stdout, etc.).

§Backpressure

The send_async method supports backpressure by awaiting until the consumer can accept the event. Implementations should use this when the consumer has bounded capacity (e.g., channel-based).

§Thread Safety

EventSink must be Send + Sync to allow sharing across async tasks. The engine may call send from multiple tasks concurrently.

§Example

use agent_core_runtime::agent::interface::{EventSink, SendError};
use agent_core_runtime::agent::UiMessage;

struct MyCustomSink { /* ... */ }

impl EventSink for MyCustomSink {
    fn send(&self, event: UiMessage) -> Result<(), SendError> {
        // Deliver event to your transport
        Ok(())
    }

    fn clone_box(&self) -> Box<dyn EventSink> {
        Box::new(MyCustomSink { /* ... */ })
    }
}

Required Methods§

Source

fn send(&self, event: UiMessage) -> Result<(), SendError>

Send an event to the consumer (non-blocking).

Returns immediately. If the consumer cannot accept the event (e.g., buffer full), returns Err(SendError).

Use this for fire-and-forget scenarios or when you have your own backpressure mechanism.

Source

fn clone_box(&self) -> Box<dyn EventSink>

Clone this sink into a boxed trait object.

Required because we need to clone sinks for internal routing but Clone is not object-safe.

Provided Methods§

Source

fn send_async( &self, event: UiMessage, ) -> Pin<Box<dyn Future<Output = Result<(), SendError>> + Send + '_>>

Send an event to the consumer (async, with backpressure).

Waits until the consumer can accept the event. This is the preferred method when backpressure is needed to avoid overwhelming slow consumers.

Default implementation calls send() and returns immediately.

Trait Implementations§

Source§

impl EventSink for Box<dyn EventSink>

Source§

fn send(&self, event: UiMessage) -> Result<(), SendError>

Send an event to the consumer (non-blocking). Read more
Source§

fn send_async( &self, event: UiMessage, ) -> Pin<Box<dyn Future<Output = Result<(), SendError>> + Send + '_>>

Send an event to the consumer (async, with backpressure). Read more
Source§

fn clone_box(&self) -> Box<dyn EventSink>

Clone this sink into a boxed trait object. Read more

Implementations on Foreign Types§

Source§

impl EventSink for Box<dyn EventSink>

Source§

fn send(&self, event: UiMessage) -> Result<(), SendError>

Source§

fn send_async( &self, event: UiMessage, ) -> Pin<Box<dyn Future<Output = Result<(), SendError>> + Send + '_>>

Source§

fn clone_box(&self) -> Box<dyn EventSink>

Implementors§