Skip to content

tokio_timer::Interval with compat layer is too fast #1285

@realcr

Description

@realcr

Hi, I tried to tokio_timer::Interval with the compat layer of Futures 3.0. It seems like it produces ticks very fast, no matter which duration I give.

Example code:

use std::time::{Duration, Instant};
use futures::future;
use futures::stream::StreamExt;
use futures::executor::LocalPool;
use tokio_timer::Interval;
use futures_util::compat::{Stream01CompatExt};

fn main() {
    let mut local_pool = LocalPool::new();

    let dur = Duration::new(1,0);
    let interval = Interval::new(Instant::now(), dur)
        .compat()
        .map(|_| ());

    let my_fut = interval.for_each(|_| {
        println!("Interval tick!");
        future::ready(())
    });
    local_pool.run_until(my_fut);
}

Expected behaviour: "Interval tick!" will be printed about every second.
Observed behaviour: "Interval tick!" is printed very quickly. Changing the numbers given to Duration::new() does not seem to change the behaviour.

My Cargo.toml:

[package]
name = "check_interval_compat"
version = "0.1.0"
authors = ["real"]
edition = "2018"

[dependencies]

futures-preview = { git = "https://github.com/rust-lang-nursery/futures-rs", rev = "a25e51e" }
futures-util-preview = { git = "https://github.com/rust-lang-nursery/futures-rs", rev = "a25e51e", features = ["compat"] }
tokio-timer = "0.2.7"

rustc version:

$ rustc --version
rustc 1.31.0-nightly (5af0bb830 2018-10-10)

Your work on Futures is highly appreciated!
Thank you for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions