Evermore is a library allows you to run an fixed number of asynchronous task repeatedly until a shutdown signal is sent out.
Usage of Evermore with Tokio, ctrlc and tracing.
```rust use stry_evermore::{Evermore, Worker};
struct Data {}
async fn main() { tracingsubscriber::fmt() .withmaxlevel(tracing::Level::TRACE) .withtarget(true) .init();
let (tx, mut rx) = tokio::sync::broadcast::channel(1);
ctrlc::set_handler(move || {
if tx.send(()).is_err() {
tracing::error!("Unable to send shutdown signal");
}
})
.expect("Unable to set CTRL-C handler");
let signal = async move { rx.recv().await.expect("Failed to listen for event") };
Evermore::new(signal, 4, Data::default(), |data: Worker<Data>| {
Box::pin(task(data))
})
.await;
}
async fn task(worker: Worker) -> Result<(), std::io::Error> { loop { tokio::time::delayfor(tokio::time::Duration::frommillis(1)).await;
if worker.should_stop() {
tracing::info!("Received shutdown signal, shutting down");
break;
}
}
Ok(())
} ```