service task + supervisor skeleton

new
Avril 4 years ago
parent 5a2c30520f
commit 85a2d880df
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -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<Result<(), SupervisorError>>
{
tokio::spawn(async move {
//TODO: Spawn slave and handle its exiting, restarting, etc according to config
Ok(())
})
}
fn spawn_slave(rx: mpsc::Receiver<()>) -> JoinHandle<Result<(), Error>>
{
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(())
})
}

@ -25,6 +25,8 @@ pub mod config;
mod builder; mod builder;
pub use builder::*; pub use builder::*;
mod host;
/// Handle to a running service. Can be used to join it or create `Channel`s. /// Handle to a running service. Can be used to join it or create `Channel`s.
#[derive(Debug)] #[derive(Debug)]
pub struct Handle pub struct Handle

Loading…
Cancel
Save