feat: add wait

This commit is contained in:
kjuulh 2025-06-25 09:47:34 +02:00
parent 9c3f2cb7f7
commit 01274c1364
2 changed files with 22 additions and 0 deletions

View File

@ -85,6 +85,12 @@ impl Mad {
self self
} }
pub fn add_wait(&mut self) -> &mut Self {
self.components.push(Waiter::default().into_component());
self
}
pub fn add_fn<F, Fut>(&mut self, f: F) -> &mut Self pub fn add_fn<F, Fut>(&mut self, f: F) -> &mut Self
where where
F: Fn(CancellationToken) -> Fut + Send + Sync + 'static, F: Fn(CancellationToken) -> Fut + Send + Sync + 'static,

View File

@ -5,10 +5,26 @@ use tokio_util::sync::CancellationToken;
use crate::{Component, MadError}; 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 { pub struct Waiter {
comp: Arc<dyn Component + Send + Sync + 'static>, comp: Arc<dyn Component + Send + Sync + 'static>,
} }
impl Default for Waiter {
fn default() -> Self {
Self {
comp: Arc::new(DefaultWaiter {}),
}
}
}
impl Waiter { impl Waiter {
pub fn new(c: Arc<dyn Component + Send + Sync + 'static>) -> Self { pub fn new(c: Arc<dyn Component + Send + Sync + 'static>) -> Self {
Self { comp: c } Self { comp: c }