background-runner 0.1.2

Run a heavy task in the background multiple times without blocking the triggering thread
Documentation
use background_runner::BackgroundRunner;
use std::thread::sleep;
use std::time::Duration;
use std::time::Instant;

fn main() {
    let mut runner_iter = 0;

    // Set up the runner, giving it the task to run
    let runner = BackgroundRunner::new(move |iter| {
        // Simulate some heavy work
        sleep(Duration::from_millis(10));
        println!("runner_iter = {runner_iter}, iter = {iter}");
        runner_iter += 1;
    });

    let start = Instant::now();
    let mut iter = 0;
    while start.elapsed().as_millis() < 100 {
        // Update the runner with the current loop iteration
        runner.update(&iter);
        iter += 1;
    }
}