Skip to main content

tea_kernel/
event.rs

1use std::future::Future;
2use std::pin::Pin;
3
4use tea_protocol::{EventEnvelope, SessionId, SessionSequence};
5
6use crate::KernelError;
7
8/// Boxed future returned by an awaited event sink.
9pub type KernelEventFuture<'a> = Pin<Box<dyn Future<Output = Result<(), KernelError>> + Send + 'a>>;
10
11/// Awaited observation destination with explicit backpressure.
12pub trait KernelEventSink: std::fmt::Debug + Send + Sync {
13    /// Returns the last accepted sequence for one continuing observation stream.
14    ///
15    /// A sink that does not preserve cursors may return `None`; a continuing
16    /// host stream should retain this value across fresh kernel instances.
17    fn last_sequence(&self, _session_id: SessionId) -> Option<SessionSequence> {
18        None
19    }
20
21    /// Accepts one canonical event after every prior event has completed.
22    fn emit(&self, event: EventEnvelope) -> KernelEventFuture<'_>;
23}
24
25/// Event sink that intentionally discards observations after awaiting the call.
26#[derive(Debug, Clone, Copy, Default)]
27pub struct DiscardEventSink;
28
29impl KernelEventSink for DiscardEventSink {
30    fn emit(&self, _event: EventEnvelope) -> KernelEventFuture<'_> {
31        Box::pin(async { Ok(()) })
32    }
33}