tatami 0.1.1

A library for creating satellites and interacting with Tatami protocols.
Documentation
use tokio::sync::{mpsc, watch};
use tokio_stream::wrappers::WatchStream;

mod commands;

pub use commands::ShojiCommand;

use crate::satellite::TatamiEvent;

#[derive(Debug, Clone)]
/// A "paper-door" to interact with the Satellite asynchronously.
/// It turns functions into event messages that communicate with the main Satellite's functions.
pub struct Shoji {
	/// The message sender from which Shoji will command the Satellite
	commander: mpsc::Sender<ShojiCommand>,
	/// The message receiver from which Shoji will reveive events
	watcher: watch::Receiver<TatamiEvent>,
}

impl Shoji {
	/// Creates a Shoji with a send stream to send commands
	#[must_use]
	pub fn new(
		commander: mpsc::Sender<ShojiCommand>,
		watcher: watch::Receiver<TatamiEvent>,
	) -> Self {
		Self { commander, watcher }
	}

	pub fn subscribe_all(&self) -> WatchStream<TatamiEvent> {
		WatchStream::new(self.watcher.clone())
	}
}