Skip to content

Commit

Permalink
Remvoe futures-util
Browse files Browse the repository at this point in the history
  • Loading branch information
DoumanAsh committed Nov 2, 2020
1 parent b0bbe9e commit 683948a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ nix = { version = "0.19", optional = true }
wasm-bindgen = "0.2"

[dev-dependencies]
futures-util = "0.3.0"
tokio_02 = { package = "tokio", version = "0.2", features = ["macros", "rt-core"] }
tokio_03 = { package = "tokio", version = "0.3.2", default-features = false, features = ["macros", "rt"] }

Expand Down
30 changes: 27 additions & 3 deletions tests/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,43 @@ async fn test_interval() {
#[cfg(feature = "stream")]
#[tokio::test]
async fn test_stream_interval() {
use futures_util::stream::StreamExt;
use futures_core::Stream;
use core::future::Future;
use core::pin::Pin;
use core::task;

pub struct Next<'a, S> {
stream: &'a mut S,
}

impl<'a, S> Next<'a, S> {
fn new(stream: &'a mut S) -> Self {
Self {
stream,
}
}
}

impl<S: Stream + Unpin> Future for Next<'_, S> {
type Output = Option<S::Item>;

fn poll(mut self: Pin<&mut Self>, ctx: &mut task::Context<'_>) -> task::Poll<Self::Output> {
let stream = Pin::new(&mut self.stream);
stream.poll_next(ctx)
}
}

let mut interval = Interval::platform_new(time::Duration::from_secs(1));

let before = time::SystemTime::now();
interval.next().await;
Next::new(&mut interval).await;
let after = time::SystemTime::now();
let diff = after.duration_since(before).unwrap();

assert!(diff.as_millis() >= 750 && diff.as_millis() <= 1_250);

let before = time::SystemTime::now();
interval.next().await;
Next::new(&mut interval).await;
let after = time::SystemTime::now();
let diff = after.duration_since(before).unwrap();

Expand Down

0 comments on commit 683948a

Please sign in to comment.