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

How to complete this demo with delay-timer? #31

Closed
zwl1619 opened this issue Dec 1, 2021 · 2 comments
Closed

How to complete this demo with delay-timer? #31

zwl1619 opened this issue Dec 1, 2021 · 2 comments

Comments

@zwl1619
Copy link

zwl1619 commented Dec 1, 2021

Code is as follow, questions are in the code.

Cargo.toml

[dependencies]
delay_timer = "0.10.1"

main.rs


use delay_timer::prelude::*;
use anyhow::Result;
use smol::Timer;
use std::time::Duration;



fn main() {
     //1、a timer start from 1 to 50000 millisecond.
            //let mut current_time= 1;

     //2、if the current_time equals some numbers, do somethings.
            if current_time =2000 {
                //do something 1
            } 
            if current_time =39999 {
                //do something 2
            } 
            //...
   
}
@elderbig
Copy link

elderbig commented Dec 3, 2021

example for delay-timer/examples/demo.rs, execute like

cargo run --package delay_timer --example demo --features=full

there is a annotation in the mod.

@BinChengZhao
Copy link
Owner

Code is as follow, questions are in the code.

Cargo.toml

[dependencies]
delay_timer = "0.10.1"

main.rs


use delay_timer::prelude::*;
use anyhow::Result;
use smol::Timer;
use std::time::Duration;



fn main() {
     //1、a timer start from 1 to 50000 millisecond.
            //let mut current_time= 1;

     //2、if the current_time equals some numbers, do somethings.
            if current_time =2000 {
                //do something 1
            } 
            if current_time =39999 {
                //do something 2
            } 
            //...
   
}

In this case you use tokio::time:sleep, which would be better suited than delay-timer, delay-timer which manages periodic tasks and controls the number of concurrent tasks.

Your need is for random time intervals, suitable for different sleep schemes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants