From 85a2d880dfc247d3e6a70777e41afd779204656f Mon Sep 17 00:00:00 2001 From: Avril Date: Mon, 10 May 2021 21:20:37 +0100 Subject: [PATCH] service task + supervisor skeleton --- src/service/host.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/service/mod.rs | 2 ++ 2 files changed, 47 insertions(+) create mode 100644 src/service/host.rs diff --git a/src/service/host.rs b/src/service/host.rs new file mode 100644 index 0000000..a77539e --- /dev/null +++ b/src/service/host.rs @@ -0,0 +1,45 @@ +//! The actual running task +use super::*; +use futures::prelude::*; + +pub type SupervisorError = (); //TODO +pub type Error = (); // TODO + +pub fn spawn_supervisor() -> JoinHandle> +{ + tokio::spawn(async move { + //TODO: Spawn slave and handle its exiting, restarting, etc according to config + Ok(()) + }) +} + +fn spawn_slave(rx: mpsc::Receiver<()>) -> JoinHandle> +{ + tokio::spawn(async move { + + let mut rx = rx + .chunk(10) // TODO: from config + .lag(duration!(10 ms)); // TODO: from config + let mut timeout = tokio::time::interval(duration!(200 ms)); // TODO: from config + loop { + tokio::select! { + block = rx.next() => { + match block { + Some(block) => { + // TODO: Process this block + }, + None => { + // Reached the end of stream, exit gracefully. + break; + } + } + } + _ = timeout.tick() => { + // Cause the `rx` to release a non-full chunk. + rx.get_mut().push_now(); + } + } + } + Ok(()) + }) +} diff --git a/src/service/mod.rs b/src/service/mod.rs index e8764c6..dc7a442 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -25,6 +25,8 @@ pub mod config; mod builder; pub use builder::*; +mod host; + /// Handle to a running service. Can be used to join it or create `Channel`s. #[derive(Debug)] pub struct Handle