I am porting one of my old C++ project to Rust. In this project, I have a function that query system information and return a std::map which I write to a SQLite database. I call this function after N minutes, where N depends on the data returned. I was using boost::fibers. The function usually takes a few seconds, and N is much larger than this value (but having a safety barrier would be nice).
I guess, I want something like this:
pub fn query_system() -> Result<SysInfo> {
// get system info and write to sqlite db.
sysinfo
}
fn main() {
// query system info after very 60 seconds to begin with.
s2 = cool_crate::call_after_N_seconds(query_system, 60); //
// d work
// do more work.
s2.update_interval(90); // now query_system is called every 90 seconds.
// do more work
// ....
}
I guess, I am looking for a timer pattern. Is this the right way to do it in Rust? Any other recommendation?