feat: add wait
This commit is contained in:
parent
9c3f2cb7f7
commit
01274c1364
@ -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<F, Fut>(&mut self, f: F) -> &mut Self
|
||||
where
|
||||
F: Fn(CancellationToken) -> Fut + Send + Sync + 'static,
|
||||
|
@ -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<dyn Component + Send + Sync + 'static>,
|
||||
}
|
||||
|
||||
impl Default for Waiter {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
comp: Arc::new(DefaultWaiter {}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Waiter {
|
||||
pub fn new(c: Arc<dyn Component + Send + Sync + 'static>) -> Self {
|
||||
Self { comp: c }
|
||||
|
Loading…
x
Reference in New Issue
Block a user