I am looking for a crate that would offer something like the following methods. Does anybody know if such a crate exists?
trait Alarm {
/// Call a callback after a given delay.
fn schedule_with_delay(&self, cb: Box<FnOnce()>, delay: Duration);
/// Call a callback once a given date&time has been reached.
fn schedule_with_timestap(&self, cb: Box<FnOnce()>, timestamp: DateTime<UTC>);
}
I don't know, but the schedule_with_delay could be implemented by spawning a thread that calls the callback after thread::sleep(some_duration) returned.
I understand, but you want to have non-blocking behaviour. I've currently no (easy) idea how to achieve this \wo spawning another thread that sleeps until the duration ends.