You've already forked pages
forked from didirus/AstralRinth
This also adds a commandline argument library (gumdrop) for dealing with indices - reseting, reconfiguring, and skipping them. I don't know which library is best for this case, but gumdrop has shorter compile times and many fewer dependencies than clap, which is why I chose it.
31 lines
649 B
Rust
31 lines
649 B
Rust
use actix_rt::time;
|
|
use actix_rt::Arbiter;
|
|
use futures::StreamExt;
|
|
|
|
pub struct Scheduler {
|
|
arbiter: Arbiter,
|
|
}
|
|
|
|
impl Scheduler {
|
|
pub fn new() -> Self {
|
|
Scheduler {
|
|
arbiter: Arbiter::new(),
|
|
}
|
|
}
|
|
|
|
pub fn run<F, R>(&mut self, interval: std::time::Duration, mut task: F)
|
|
where
|
|
F: FnMut() -> R + Send + 'static,
|
|
R: std::future::Future<Output = ()> + Send + 'static,
|
|
{
|
|
let future = time::interval(interval).for_each_concurrent(2, move |_| task());
|
|
self.arbiter.send(future);
|
|
}
|
|
}
|
|
|
|
impl Drop for Scheduler {
|
|
fn drop(&mut self) {
|
|
self.arbiter.stop();
|
|
}
|
|
}
|