diff --git a/crates/mad/src/lib.rs b/crates/mad/src/lib.rs index aa2478f..dcd9c07 100644 --- a/crates/mad/src/lib.rs +++ b/crates/mad/src/lib.rs @@ -85,6 +85,12 @@ impl Mad { self } + pub fn add_wait(&mut self) -> &mut Self { + self.components.push(Waiter::default().into_component()); + + self + } + pub fn add_fn(&mut self, f: F) -> &mut Self where F: Fn(CancellationToken) -> Fut + Send + Sync + 'static, diff --git a/crates/mad/src/waiter.rs b/crates/mad/src/waiter.rs index 982ffb6..f54f2e1 100644 --- a/crates/mad/src/waiter.rs +++ b/crates/mad/src/waiter.rs @@ -5,10 +5,26 @@ use tokio_util::sync::CancellationToken; use crate::{Component, MadError}; +pub struct DefaultWaiter {} +#[async_trait] +impl Component for DefaultWaiter { + async fn run(&self, _cancellation_token: CancellationToken) -> Result<(), MadError> { + panic!("should never be called"); + } +} + pub struct Waiter { comp: Arc, } +impl Default for Waiter { + fn default() -> Self { + Self { + comp: Arc::new(DefaultWaiter {}), + } + } +} + impl Waiter { pub fn new(c: Arc) -> Self { Self { comp: c }