1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
use core::{future::Future, time::Duration}; use futures_core::stream::Stream; pub trait Timer: Sized { type Error; type Timeout: Future<Output = Result<Self, Self::Error>>; type Interval: Stream<Item = Result<(), Self::Error>>; fn timeout(self, duration: Duration) -> Self::Timeout; fn interval(self, duration: Duration) -> Self::Interval; } /* TODO: Use this pub trait Timer { type Error; fn timeout( self: Pin<Self>, duration: Time, ) -> impl StableFuture<Item = (), Error = Self::Error> + '_; fn interval( self: Pin<Self>, duration: Time, ) -> impl StableStream<Item = (), Error = Self::Error> + '_; } */