Crates.io | background-runner |
lib.rs | background-runner |
version | 0.1.2 |
created_at | 2025-09-05 21:06:03.576787+00 |
updated_at | 2025-09-07 18:28:22.211692+00 |
description | Run a heavy task in the background multiple times without blocking the triggering thread |
homepage | |
repository | https://codeberg.org/CoffeJunkStudio/background-runner |
max_upload_size | |
id | 1826205 |
size | 25,362 |
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).