diff --git a/Cargo.toml b/Cargo.toml index 923b932..09821bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ticked_async_executor" -version = "0.2.0" +version = "0.2.1" authors = ["coder137"] edition = "2021" description = "Local executor that runs woken async tasks when it is ticked" diff --git a/src/split_ticked_async_executor.rs b/src/split_ticked_async_executor.rs index e0fda13..5371057 100644 --- a/src/split_ticked_async_executor.rs +++ b/src/split_ticked_async_executor.rs @@ -89,7 +89,7 @@ where pub fn create_timer(&self) -> TickedTimer { let tick_recv = self.rx_tick_event.clone(); - TickedTimer { tick_recv } + TickedTimer::new(tick_recv) } pub fn tick_channel(&self) -> tokio::sync::watch::Receiver { diff --git a/src/ticked_timer.rs b/src/ticked_timer.rs index 25172ea..ed108fe 100644 --- a/src/ticked_timer.rs +++ b/src/ticked_timer.rs @@ -1,8 +1,12 @@ pub struct TickedTimer { - pub tick_recv: tokio::sync::watch::Receiver, + tick_recv: tokio::sync::watch::Receiver, } impl TickedTimer { + pub fn new(tick_recv: tokio::sync::watch::Receiver) -> Self { + Self { tick_recv } + } + pub async fn sleep_for(mut self, mut duration_in_ms: f64) { loop { let _r = self.tick_recv.changed().await;