work-manager

Crates.iowork-manager
lib.rswork-manager
version0.1.3
created_at2025-11-20 11:51:28.734163+00
updated_at2025-12-18 12:36:43.202698+00
descriptionA library for managing asynchronous work tasks.
homepagehttps://github.com/luukgoossen/work-manager
repositoryhttps://github.com/luukgoossen/work-manager
max_upload_size
id1941841
size28,035
Luuk Goossen (luukgoossen)

documentation

README

Work Manager

work-manager is a Rust library designed to simplify the management of asynchronous tasks. It allows you to define Jobs, chain them into Sequences, and schedule them using a WorkManager.

Features

  • Job Abstraction: Implement the Job trait to define units of work.
  • Job Sequencing: Chain jobs together using .then(), passing results from one to the next.
  • Task Management: Use WorkManager to enqueue one-off or periodic jobs.
  • Cancellation: Easily cancel jobs by name.

Installation

Add this to your Cargo.toml:

[dependencies]
work-manager = "0.1.0"
tokio = { version = "1", features = ["rt", "time", "macros"] }

Usage

use work_manager::{Job, WorkManager};
use std::time::Duration;

struct PrintJob {
    message: String,
}

impl Job for PrintJob {
    type Output = ();
    type Error = std::io::Error;

    async fn run(self) -> Result<Self::Output, Self::Error> {
        println!("{}", self.message);
        Ok(())
    }
}

#[tokio::main]
async fn main() {
    let mut manager = WorkManager::new();

    // Enqueue a single job
    manager.enqueue("print_hello", PrintJob { message: "Hello".into() }, false);

    // Enqueue a periodic job
    manager.enqueue_periodic(
        "print_tick",
        PrintJob { message: "Tick".into() },
        Duration::from_secs(1),
        false,
        false
    );
}

License

This project is licensed under the MIT License.

Commit count: 0

cargo fmt