Crates.io | sched-callback |
lib.rs | sched-callback |
version | 0.1.2 |
source | src |
created_at | 2024-05-18 15:25:15.092618 |
updated_at | 2024-05-25 01:30:19.625371 |
description | Rust library for async callback scheduling |
homepage | |
repository | https://github.com/argnmp/sched-callback |
max_upload_size | |
id | 1244352 |
size | 18,287 |
A scheduler that executes async callback at certain point.
Create scheduler using queue::SchedQueue
let sq = SchedQueue::new();
Callback type:
type Callback = Box<dyn Fn() -> Pin<Box<dyn Future<Output = ()> + Send + 'static>> + Send + 'static>;
Add task with callback. Callback will be triggered 1 second after the task is added, and will be rescheduled for 10 times after the callback has been triggered.
sq.add(Task::new(SchedType::Delay(Duration::from_secs(1), 10), Box::new(move || {
Box::pin(async move {
println!("hello world");
})
}))).await;
Two types of task can be added to queue. SchedType::Timestamp(SystemTime)
specifies the exact
timestamp that the callback will be triggered at. SchedType::Delay(Duration, usize)
specifies
when the callback will be triggered after the task is added and how many times will it be
rescheduled.