Skip to main content

liminal_cli/network/
tap.rs

1//! The long-lived tap contract, with reception separated from its close signal.
2
3use super::RailError;
4use serde_json::Value;
5use std::fmt::Debug;
6use std::sync::Arc;
7
8/// A blocking tap reader. One receive consumes one wire record.
9pub trait TapReader: Debug + Send {
10    /// Blocks until a record arrives or the subscription ends.
11    ///
12    /// # Errors
13    /// Returns the reader's terminal or decoding failure in words.
14    fn receive(&self) -> Result<Value, RailError>;
15}
16
17/// A separately held signal that releases a blocked tap reader.
18pub trait TapCloser: Debug + Send + Sync {
19    /// Ends the subscription without a timer or another record.
20    ///
21    /// # Errors
22    /// Returns the close failure, after signaling every wait it owns.
23    fn close(&self) -> Result<(), RailError>;
24}
25
26/// A reader and its independently held close signal.
27#[derive(Debug)]
28pub struct TapSubscription {
29    /// The owned, blocking receive half.
30    pub reader: Box<dyn TapReader>,
31    /// The close signal, shareable with service teardown.
32    pub closer: Arc<dyn TapCloser>,
33}