Skip to main content

Module event_stream

Module event_stream 

Source
Expand description

Event Stream - Real-time Event Push System

This module provides a publish-subscribe event system for real-time event pushing, similar to Docker’s docker events and docker logs -f functionality.

§Features

  • Publish-subscribe pattern with multiple publishers and subscribers
  • Event filtering by type and resource ID
  • Event history with optional replay
  • Backpressure handling for slow consumers
  • MCP (Model Context Protocol) compatible progress events via McpProgressPayload

§Example

use ipckit::{EventBus, Event, EventFilter};

let bus = EventBus::new(Default::default());
let publisher = bus.publisher();

// Subscribe to task events
let mut subscriber = bus.subscribe(
    EventFilter::new().event_type("task.*")
);

// Publish an event
publisher.publish(Event::new("task.started", serde_json::json!({"task_id": "123"})));

// Receive the event
if let Some(event) = subscriber.try_recv() {
    println!("Received: {:?}", event);
}

§MCP progress events

use ipckit::{EventBus, EventFilter, event_types};

let bus = EventBus::new(Default::default());
let publisher = bus.publisher();

// Subscribe using the MCP-progress convenience filter
let subscriber = bus.subscribe(EventFilter::new().mcp_progress());

// Publish an MCP-compatible progress notification
publisher.mcp_progress("render-token-abc", 42.0, Some(100.0), Some("Rendering frame 42/100"));

if let Some(event) = subscriber.try_recv() {
    let payload: ipckit::McpProgressPayload =
        serde_json::from_value(event.data).unwrap();
    assert_eq!(payload.progress_token, "render-token-abc");
}

Modules§

event_types
Standard event type constants.

Structs§

Event
An event that can be published and subscribed to.
EventBus
The main event bus for publish-subscribe communication.
EventBusConfig
Configuration for the event bus.
EventFilter
Event filter for subscribing to specific events.
EventPublisher
Event publisher for sending events to the bus.
EventSubscriber
Event subscriber for receiving events from the bus.
McpProgressPayload
Progress notification payload compatible with the MCP specification’s notifications/progress message shape.

Enums§

SlowConsumerPolicy
Policy for handling slow consumers.

Type Aliases§

EventId
A unique event identifier.