coreon_eip/delay.rs
1//! DelayBy — sleep for a fixed duration before continuing.
2
3use async_trait::async_trait;
4use coreon_core::{Exchange, Processor, Result};
5use std::{sync::Arc, time::Duration};
6
7pub struct DelayBy {
8 duration: Duration,
9}
10
11impl DelayBy {
12 pub fn new(duration: Duration) -> Arc<Self> {
13 Arc::new(Self { duration })
14 }
15}
16
17#[async_trait]
18impl Processor for DelayBy {
19 async fn process(&self, _exchange: &mut Exchange) -> Result<()> {
20 tokio::time::sleep(self.duration).await;
21 Ok(())
22 }
23}