use core::future::Future;
use std::time::{Duration, Instant};
use super::{Delay, DelayUntil, Timeout, TimeoutAt};
pub trait FutureExt: Future {
fn timeout(self, dur: Duration) -> Timeout<Self>
where
Self: Sized,
{
Timeout::new(self, dur)
}
fn timeout_at(self, deadline: Instant) -> TimeoutAt<Self>
where
Self: Sized,
{
TimeoutAt::new(self, deadline)
}
fn delay(self, dur: Duration) -> Delay<Self>
where
Self: Sized,
{
Delay::new(self, dur)
}
fn delay_until(self, deadline: Instant) -> DelayUntil<Self>
where
Self: Sized,
{
DelayUntil::new(self, deadline)
}
}
impl<T> FutureExt for T where T: Future {}