延迟任务的时间管理器。类似于 crontab,但支持同步异步任务的调度,并支持动态添加、取消和删除。
Time-manager of delayed tasks. Like crontab, but synchronous asynchronous tasks are possible, and dynamic add/cancel/remove is supported.
delay-timer is a task manager based on a time wheel algorithm, which makes it easy to manage timed tasks, or to periodically execute arbitrary tasks such as closures.
The underlying runtime is based on the optional smol and tokio, and you can build your application with either one.
The minimum-supported version of rustc is 1.56.
Except for the simple execution in a few seconds, you can also specify a specific date, such as Sunday at 4am to execute a backup task.
…Use in asynchronous contexts.
…Capture the specified environment information and build the closure & task:
#[macro_use]
use delay_timer::prelude::*;
use std::sync::atomic::{
AtomicUsize,
Ordering::{Acquire, Release},
};
use std::sync::Arc;
let delay_timer = DelayTimer::new();
let share_num = Arc::new(AtomicUsize::new(0));
let share_num_bunshin = share_num.clone();
let body = move || {
share_num_bunshin.fetch_add(1, Release);
};
let task = TaskBuilder::default()
.set_frequency_count_down_by_cron_str(expression, 3)
.set_task_id(1)
.spawn_routine(body)?;
delay_timer.add_task(task)?;
Building customized-dynamic future tasks:
…There's a lot more in the [examples] directory.
Licensed under either of
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
暂无开放 Issues,或尚未同步最近议题。