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

"set_frequency_once" always execute immediately. #38

Closed
gamife opened this issue Apr 22, 2022 · 3 comments · Fixed by #39
Closed

"set_frequency_once" always execute immediately. #38

gamife opened this issue Apr 22, 2022 · 3 comments · Fixed by #39

Comments

@gamife
Copy link

gamife commented Apr 22, 2022

Describe the bug
set_frequency_once_by_seconds(5)
The function is executed immediately instead of being delayed for some time

To Reproduce

use std::time::Duration;

use delay_timer::prelude::{DelayTimerBuilder, ScheduleIteratorTimeZone, TaskBuilder};

#[tokio::main]
async fn main() {
    let body = || async {
        println!("running: {}", chrono::Local::now());
    };

    println!("start: {}", chrono::Local::now());
    let new_task = TaskBuilder::default()
        .set_task_id(1)
        .set_schedule_iterator_time_zone(ScheduleIteratorTimeZone::Local)
        .set_frequency_once_by_seconds(5)
        .set_maximum_parallel_runnable_num(1)
        .spawn_async_routine(body)
        .unwrap();

    let delay_timer = DelayTimerBuilder::default().build();
    delay_timer.add_task(new_task).unwrap();

    tokio::time::sleep(Duration::from_secs(15)).await;
    println!("end: {}", chrono::Local::now());
}
delay_timer = { version = "0.11.0", features = ["status-report"] }
chrono = "0.4.19"
tokio = { version = "1", features = ["full"] }

Result

start: 2022-04-22 10:56:01.732017356 +08:00
running: 2022-04-22 10:56:02.793417770 +08:00
end: 2022-04-22 10:56:16.796830865 +08:00

Expected behavior
Expect a five-second delay.

Desktop (please complete the following information):

  • OS: Linux version 3.10.0-957.el7.x86_64 (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) )
  • Rust: rustc 1.59.0 (9d1b2106e 2022-02-23)
@BinChengZhao
Copy link
Owner

BinChengZhao commented Apr 23, 2022

Expected behavior Expect a five-second delay.

Desktop (please complete the following information):

  • OS: Linux version 3.10.0-957.el7.x86_64 (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) )
  • Rust: rustc 1.59.0 (9d1b2106e 2022-02-23)

Friend your scene I have reproduced,

The specific behavior is as follows:

First-time immediate execution,
From the second time onwards, the execution is delayed at regular intervals.

I will find time to adjust the program behavior in the near future, thanks for your feedback!

@BinChengZhao
Copy link
Owner

@gamife Fix at V0.11.2, I look forward to your feedback on successful use.

:)

@BinChengZhao BinChengZhao linked a pull request May 9, 2022 that will close this issue
@Xiaobaishushu25
Copy link

可以实现这种这种效果吗?public void schedule(TimerTask task, long delay, long period):创建完成后延迟delay执行一次,随后每period执行一次.
另外好像要么执行一次(set_frequency_once),要么指定执行次数,有无限执行的选择不?

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

Successfully merging a pull request may close this issue.

3 participants