switch to smol::Timer

master
dignifiedquire 5 years ago
parent f5fa0d7e4e
commit ab9d6554aa

@ -27,7 +27,6 @@ default = [
"crossbeam-channel", "crossbeam-channel",
"crossbeam-deque", "crossbeam-deque",
"crossbeam-queue", "crossbeam-queue",
"futures-timer",
"kv-log-macro", "kv-log-macro",
"log", "log",
"mio", "mio",
@ -37,7 +36,7 @@ default = [
"smol", "smol",
] ]
docs = ["attributes", "unstable", "default"] docs = ["attributes", "unstable", "default"]
unstable = ["std", "broadcaster", "futures-timer"] unstable = ["std", "broadcaster"]
attributes = ["async-attributes"] attributes = ["async-attributes"]
std = [ std = [
"alloc", "alloc",
@ -64,7 +63,6 @@ crossbeam-queue = { version = "0.2.0", optional = true }
crossbeam-utils = { version = "0.7.2", optional = true } crossbeam-utils = { version = "0.7.2", optional = true }
futures-core = { version = "0.3.4", optional = true, default-features = false } futures-core = { version = "0.3.4", optional = true, default-features = false }
futures-io = { version = "0.3.4", optional = true } futures-io = { version = "0.3.4", optional = true }
futures-timer = { version = "3.0.2", optional = true }
kv-log-macro = { version = "1.0.4", optional = true } kv-log-macro = { version = "1.0.4", optional = true }
log = { version = "0.4.8", features = ["kv_unstable"], optional = true } log = { version = "0.4.8", features = ["kv_unstable"], optional = true }
memchr = { version = "2.3.3", optional = true } memchr = { version = "2.3.3", optional = true }

@ -2,8 +2,8 @@ use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
use std::time::Duration; use std::time::Duration;
use futures_timer::Delay;
use pin_project_lite::pin_project; use pin_project_lite::pin_project;
use smol::Timer;
use crate::task::{Context, Poll}; use crate::task::{Context, Poll};
@ -14,13 +14,13 @@ pin_project! {
#[pin] #[pin]
future: F, future: F,
#[pin] #[pin]
delay: Delay, delay: Timer,
} }
} }
impl<F> DelayFuture<F> { impl<F> DelayFuture<F> {
pub fn new(future: F, dur: Duration) -> DelayFuture<F> { pub fn new(future: F, dur: Duration) -> DelayFuture<F> {
let delay = Delay::new(dur); let delay = Timer::after(dur);
DelayFuture { future, delay } DelayFuture { future, delay }
} }

@ -1,11 +1,11 @@
use std::error::Error; use std::error::Error;
use std::fmt; use std::fmt;
use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
use std::time::Duration; use std::time::Duration;
use std::future::Future;
use futures_timer::Delay;
use pin_project_lite::pin_project; use pin_project_lite::pin_project;
use smol::Timer;
use crate::task::{Context, Poll}; use crate::task::{Context, Poll};
@ -33,11 +33,7 @@ pub async fn timeout<F, T>(dur: Duration, f: F) -> Result<T, TimeoutError>
where where
F: Future<Output = T>, F: Future<Output = T>,
{ {
let f = TimeoutFuture { TimeoutFuture::new(f, dur).await
future: f,
delay: Delay::new(dur),
};
f.await
} }
pin_project! { pin_project! {
@ -46,14 +42,17 @@ pin_project! {
#[pin] #[pin]
future: F, future: F,
#[pin] #[pin]
delay: Delay, delay: Timer,
} }
} }
impl<F> TimeoutFuture<F> { impl<F> TimeoutFuture<F> {
#[allow(dead_code)] #[allow(dead_code)]
pub(super) fn new(future: F, dur: Duration) -> TimeoutFuture<F> { pub(super) fn new(future: F, dur: Duration) -> TimeoutFuture<F> {
TimeoutFuture { future: future, delay: Delay::new(dur) } TimeoutFuture {
future,
delay: Timer::after(dur),
}
} }
} }

@ -1,10 +1,10 @@
use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
use std::time::Duration; use std::time::Duration;
use std::future::Future;
use futures_timer::Delay;
use pin_project_lite::pin_project; use pin_project_lite::pin_project;
use smol::Timer;
use crate::io; use crate::io;
@ -37,7 +37,7 @@ where
F: Future<Output = io::Result<T>>, F: Future<Output = io::Result<T>>,
{ {
Timeout { Timeout {
timeout: Delay::new(dur), timeout: Timer::after(dur),
future: f, future: f,
} }
.await .await
@ -53,7 +53,7 @@ pin_project! {
#[pin] #[pin]
future: F, future: F,
#[pin] #[pin]
timeout: Delay, timeout: Timer,
} }
} }

@ -319,8 +319,8 @@ impl AsRawFd for UnixDatagram {
impl FromRawFd for UnixDatagram { impl FromRawFd for UnixDatagram {
unsafe fn from_raw_fd(fd: RawFd) -> UnixDatagram { unsafe fn from_raw_fd(fd: RawFd) -> UnixDatagram {
let datagram = std::os::unix::net::UnixDatagram::from_raw_fd(fd); let datagram = Async::<StdUnixDatagram>::from_raw_fd(fd);
datagram.into() UnixDatagram { watcher: datagram }
} }
} }

@ -1,10 +1,10 @@
use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
use std::time::Duration; use std::time::Duration;
use crate::future::Future;
use crate::stream::Stream; use crate::stream::Stream;
use futures_timer::Delay; use smol::Timer;
/// Creates a new stream that yields at a set interval. /// Creates a new stream that yields at a set interval.
/// ///
@ -45,7 +45,7 @@ use futures_timer::Delay;
#[cfg_attr(feature = "docs", doc(cfg(unstable)))] #[cfg_attr(feature = "docs", doc(cfg(unstable)))]
pub fn interval(dur: Duration) -> Interval { pub fn interval(dur: Duration) -> Interval {
Interval { Interval {
delay: Delay::new(dur), delay: Timer::after(dur),
interval: dur, interval: dur,
} }
} }
@ -60,7 +60,7 @@ pub fn interval(dur: Duration) -> Interval {
#[cfg_attr(feature = "docs", doc(cfg(unstable)))] #[cfg_attr(feature = "docs", doc(cfg(unstable)))]
#[derive(Debug)] #[derive(Debug)]
pub struct Interval { pub struct Interval {
delay: Delay, delay: Timer,
interval: Duration, interval: Duration,
} }
@ -72,7 +72,7 @@ impl Stream for Interval {
return Poll::Pending; return Poll::Pending;
} }
let interval = self.interval; let interval = self.interval;
self.delay.reset(interval); std::mem::replace(&mut self.delay, Timer::after(interval));
Poll::Ready(Some(())) Poll::Ready(Some(()))
} }
} }

@ -3,6 +3,7 @@ use core::pin::Pin;
use core::time::Duration; use core::time::Duration;
use pin_project_lite::pin_project; use pin_project_lite::pin_project;
use smol::Timer;
use crate::stream::Stream; use crate::stream::Stream;
use crate::task::{Context, Poll}; use crate::task::{Context, Poll};
@ -14,7 +15,7 @@ pin_project! {
#[pin] #[pin]
stream: S, stream: S,
#[pin] #[pin]
delay: futures_timer::Delay, delay: Timer,
delay_done: bool, delay_done: bool,
} }
} }
@ -23,7 +24,7 @@ impl<S> Delay<S> {
pub(super) fn new(stream: S, dur: Duration) -> Self { pub(super) fn new(stream: S, dur: Duration) -> Self {
Delay { Delay {
stream, stream,
delay: futures_timer::Delay::new(dur), delay: Timer::after(dur),
delay_done: false, delay_done: false,
} }
} }

@ -2,8 +2,8 @@ use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
use std::time::Duration; use std::time::Duration;
use futures_timer::Delay;
use pin_project_lite::pin_project; use pin_project_lite::pin_project;
use smol::Timer;
use crate::stream::Stream; use crate::stream::Stream;
use crate::task::{Context, Poll}; use crate::task::{Context, Poll};
@ -25,7 +25,7 @@ pin_project! {
#[pin] #[pin]
blocked: bool, blocked: bool,
#[pin] #[pin]
delay: Delay, delay: Timer,
} }
} }
@ -35,7 +35,7 @@ impl<S: Stream> Throttle<S> {
stream, stream,
duration, duration,
blocked: false, blocked: false,
delay: Delay::new(Duration::default()), delay: Timer::after(Duration::default()),
} }
} }
} }
@ -59,7 +59,7 @@ impl<S: Stream> Stream for Throttle<S> {
Poll::Ready(None) => Poll::Ready(None), Poll::Ready(None) => Poll::Ready(None),
Poll::Ready(Some(v)) => { Poll::Ready(Some(v)) => {
*this.blocked = true; *this.blocked = true;
this.delay.reset(*this.duration); std::mem::replace(&mut *this.delay, Timer::after(*this.duration));
Poll::Ready(Some(v)) Poll::Ready(Some(v))
} }
} }

@ -4,8 +4,8 @@ use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
use std::time::Duration; use std::time::Duration;
use futures_timer::Delay;
use pin_project_lite::pin_project; use pin_project_lite::pin_project;
use smol::Timer;
use crate::stream::Stream; use crate::stream::Stream;
use crate::task::{Context, Poll}; use crate::task::{Context, Poll};
@ -17,13 +17,13 @@ pin_project! {
#[pin] #[pin]
stream: S, stream: S,
#[pin] #[pin]
delay: Delay, delay: Timer,
} }
} }
impl<S: Stream> Timeout<S> { impl<S: Stream> Timeout<S> {
pub(crate) fn new(stream: S, dur: Duration) -> Self { pub(crate) fn new(stream: S, dur: Duration) -> Self {
let delay = Delay::new(dur); let delay = Timer::after(dur);
Self { stream, delay } Self { stream, delay }
} }

Loading…
Cancel
Save