2 releases
0.1.1 | May 9, 2019 |
---|---|
0.1.0 | May 9, 2019 |
#24 in #task-scheduler
54 downloads per month
Used in danmuji
16KB
240 lines
“I'm late! I'm late! For a very important date!”
by “The White Rabbit” 『Alice's Adventures in Wonderland』
About
white_rabbit
schedules your tasks and can repeat them!
One funny use case are chat bots, e.g. a remind me-command that might be repeated after a user-specified time.
We are using chrono's DateTime<Utc>
, enabling you to serialise and thus backup currently
running tasks, in case you want to shutdown/restart your application,
constructing a new scheduler is doable. However, please make sure your internal
clock is synced.
Everyone is welcome to contribute, check out
the CONTRIBUTING.md
for further guidance.
Example
Let's have a look at a code-example:
use white_rabbit::{DateResult, Duration, Scheduler};
fn main() {
let mut scheduler = Scheduler::new(4);
scheduler.add_task_duration(Duration::seconds(5), |_| {
println!("I'm here!");
DateResult::Done
});
}
Precision
The scheduler sleeps when unneeded. Due to preemption or different implementations across operating systems, it may occur that the scheduler will sleep longer than intended.
Be aware, an incorrect system clock may lead to tasks being run earlier or later.
Installation
Add this to your Cargo.toml
:
[dependencies]
white_rabbit = "0.1.0"
Dependencies
~2.7–5MB
~84K SLoC