background-runner 0.1.1

Run a heavy task in the background multiple times without blocking the triggering thread
Documentation
  • Coverage
  • 85.71%
    6 out of 7 items documented1 out of 6 items with examples
  • Size
  • Source code size: 21.2 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.46 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 20s Average build duration of successful builds.
  • all releases: 19s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • dezajno Cryptjar

Background Runner

The purpose of this crate is to run a heavy task in the background multiple times without blocking the triggering thread. The motivating use case is to periodically write to a file from a game loop.

// Create a background runner and give it a task to run
let runner = BackgroundRunner::new(move |state| {
    // Heavy work goes here
});

// Some state to repeatedly pass to the runner.
// This can be anything that's Send + 'static
let state = 42;
loop {
    // Light work goes here

    // Trigger the runner if it's not busy currently
    runner.update(&state);
}

The update() method is guaranteed to never block the calling thread. It will only trigger the runner's task if it's not currently running (i.e. busy with processing a previous run request).