Function Timer method or library

#1

Is there an easy way to only execute a function or block of code every n seconds without having to do the standard if cur_time > last_time + duration logic?

#2

Well, you could do something like this:

use std::thread;
use std::time::Duration;
for _ in 0..n {
    thread::spawn(move || {/**/});
    thread::sleep(Duration::from_millis(1000));
}

But that would lock you to not working with references to local scope objects, which might midigate you. Otherwise you will probably have to use your thread::sleep(wanted - elapsed); logic either inline or in a helper function taking <F: FnMut()>.