sched_callback/lib.rs
1//! # sched-callback
2//! A scheduler that executes async callback at certain point.
3//!
4//! ## Overview
5//! - Works on tokio runtime.
6//! - Lightweight scheduler that only one task is executed in one task queue.
7//!
8//! ## Usage
9//! Create scheduler using `queue::SchedQueue`
10//! ```rust,no_run
11//! let sq = SchedQueue::new();
12//! ```
13//!
14//! Callback type:
15//! ```rust,no_run
16//! type Callback = Box<dyn Fn() -> Pin<Box<dyn Future<Output = ()> + Send + 'static>> + Send + 'static>;
17//! ````
18//!
19//! Add task with callback.
20//! Callback will be triggered 1 second after the task is added, and will be rescheduled for 10 times after the callback has been triggered.
21//! ```rust,no_run
22//! sq.add(Task::new(SchedType::Delay(Duration::from_secs(1), 10), Box::new(move || {
23//! Box::pin(async move {
24//! println!("hello world");
25//! })
26//! }))).await;
27//! ````
28//!
29//! Two types of task can be added to queue. `SchedType::Timestamp(SystemTime)` specifies the exact
30//! timestamp that the callback will be triggered at. `SchedType::Delay(Duration, usize)` specifies
31//! when the callback will be triggered after the task is added and how many times will it be
32//! rescheduled.
33
34pub mod task;
35pub mod queue;
36pub mod message;