Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interval::reset_immediately() is not immediately ready #6940

Closed
erikgrinaker opened this issue Oct 28, 2024 · 1 comment
Closed

Interval::reset_immediately() is not immediately ready #6940

erikgrinaker opened this issue Oct 28, 2024 · 1 comment
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-time Module: tokio/time

Comments

@erikgrinaker
Copy link

Version

v1.38.1

Platform

macOS 15 on arm64

Darwin 24.0.0 Darwin Kernel Version 24.0.0: Tue Sep 24 23:37:25 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T6030 arm64 arm Darwin

Description

Interval::reset_immediately() is not immediately ready. It appears to take 1 millisecond (the timer resolution).

#[tokio::test]
async fn test_reset_immediately() {
    use futures::FutureExt as _;
    use tokio::time::{Duration, Instant};

    let mut ticker = tokio::time::interval(Duration::from_secs(1));
    ticker.tick().await;

    ticker.reset_immediately();
    assert!(ticker.tick().now_or_never().is_some()); // fails

    // Time a reset. Outputs > 1 millisecond.
    let start = Instant::now();
    ticker.reset_immediately();
    ticker.tick().await;
    println!("{}", Instant::now().duration_since(start).as_secs_f64())
}

I expect the future to be immediately ready.

@erikgrinaker erikgrinaker added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Oct 28, 2024
@Darksonn Darksonn added the M-time Module: tokio/time label Oct 28, 2024
@Darksonn
Copy link
Contributor

Darksonn commented Oct 28, 2024

This is due to duration-zero sleeps sleeping until the next tick. Closing as duplicate of #6866.

@Darksonn Darksonn closed this as not planned Won't fix, can't repro, duplicate, stale Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-time Module: tokio/time
Projects
None yet
Development

No branches or pull requests

2 participants