use gloo_timers::future::TimeoutFuture;
use send_wrapper::SendWrapper;
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
time::Duration,
};
#[derive(Debug)]
pub struct Delay(SendWrapper<TimeoutFuture>);
impl Delay {
#[inline]
pub fn new(dur: Duration) -> Delay {
Self(SendWrapper::new(TimeoutFuture::new(dur.as_millis() as u32)))
}
#[inline]
pub fn reset(&mut self, dur: Duration) {
*self = Delay::new(dur);
}
}
impl Future for Delay {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
Pin::new(&mut *Pin::into_inner(self).0).poll(cx)
}
}