use futures::prelude::*;
use std::fmt;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::time::{Duration, Instant};
#[must_use = "futures do nothing unless awaited"]
pub struct Delay {
inner: Pin<Box<dyn runtime_raw::Delay>>,
}
impl Delay {
#[inline]
pub fn new(dur: Duration) -> Self {
let inner = runtime_raw::current_runtime().new_delay(dur);
Self { inner }
}
#[inline]
pub fn new_at(at: Instant) -> Self {
let inner = runtime_raw::current_runtime().new_delay_at(at);
Self { inner }
}
}
impl fmt::Debug for Delay {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
fmt::Debug::fmt(&self.inner, f)
}
}
impl Future for Delay {
type Output = Instant;
#[inline]
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
self.inner.poll_unpin(cx)
}
}