[−][src]Crate heng_rs
A simple schedule task runner on tokio runtime that support one way message pushing.
example:
use std::time::Duration; use heng_rs::{Scheduler, Time, ToDuration}; struct TestTask(u32); impl Scheduler for TestTask { type Message = u32; } #[tokio::main] async fn main() -> std::io::Result<()> { let task = TestTask(0); let time = Time::new() .every(1.d()) .plus(2.h()) .plus(3.m()) .plus(4.s()); // run task with a 1 day, 2 hours, 3 minutes and 4 seconds interval. let addr = task.start(time, |task, ctx| { if let Some(msg) = ctx.get_msg_front() { /* do something with message */ } // do something with task. task.0 += 1; // run a future. async { Ok::<(),()>(()) } }); // use address to push message to task's context; addr.send(1u32).await; Ok(()) }
Structs
Context | |
SchedulerSender | |
SendError | The error type for |
SharedSchedulerSender | |
Time |
Traits
Scheduler | |
ToDuration |