mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
Update Tokio to use std::future. (#1120)
A first pass at updating Tokio to use `std::future`. Implementations of `Future` from the futures crate are updated to implement `Future` from std. Implementations of `Stream` are moved to a feature flag. This commits disables a number of crates that have not yet been updated.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
use crate::clock;
|
||||
use crate::Delay;
|
||||
use futures::{try_ready, Future, Poll, Stream};
|
||||
use futures_core::Stream;
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::task::{self, Poll};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
/// A stream representing notifications at fixed interval
|
||||
@@ -53,20 +56,20 @@ impl Interval {
|
||||
|
||||
impl Stream for Interval {
|
||||
type Item = Instant;
|
||||
type Error = crate::Error;
|
||||
|
||||
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
|
||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Option<Self::Item>> {
|
||||
// Wait for the delay to be done
|
||||
let _ = try_ready!(self.delay.poll());
|
||||
ready!(Pin::new(&mut self.delay).poll(cx));
|
||||
|
||||
// Get the `now` by looking at the `delay` deadline
|
||||
let now = self.delay.deadline();
|
||||
|
||||
// The next interval value is `duration` after the one that just
|
||||
// yielded.
|
||||
self.delay.reset(now + self.duration);
|
||||
let next = now + self.duration;
|
||||
self.delay.reset(next);
|
||||
|
||||
// Return the current instant
|
||||
Ok(Some(now).into())
|
||||
Poll::Ready(Some(now))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user