Use smol::Timer::interval for time::Every

This commit is contained in:
Héctor Ramón Jiménez 2021-01-15 21:07:37 +01:00
parent 803cc88483
commit 9da0a3de54

View File

@ -35,16 +35,8 @@ where
_input: futures::stream::BoxStream<'static, E>, _input: futures::stream::BoxStream<'static, E>,
) -> futures::stream::BoxStream<'static, Self::Output> { ) -> futures::stream::BoxStream<'static, Self::Output> {
use futures::stream::StreamExt; use futures::stream::StreamExt;
use std::time::Instant;
let duration = self.0; smol::Timer::interval(self.0).boxed()
futures::stream::unfold(Instant::now(), move |last_tick| async move {
let last_tick = smol::Timer::at(last_tick + duration).await;
Some((last_tick, last_tick))
})
.boxed()
} }
} }