work_pool 0.1.0

A simple implementation of a work queue wrapped by a thread pool.
Documentation
  • Coverage
  • 55.56%
    5 out of 9 items documented0 out of 6 items with examples
  • Size
  • Source code size: 9.2 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.57 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Wilkua/work_pool
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Wilkua

WorkPool

A super simple implementation of a work queue wrapped by a thread pool.

The goal of this package is to have a quick way of creating a thread pool with a work queue backing for quick projects.

Example

use std::sync::Arc;
use work_pool::WorkPool;

fn main() {
    // Specify number of threads and work queue capacity
    // Work queue capacity is workload based, but a good
    // estimate might be 2 or 4 times the number of threads
    let mut pool = WorkPool::new(8, 64);

    // Set the executor function and star tthe work listener
    pool.set_executor_and_start(|work| {
        // Work is the data sent by `dispatch`
    });

    loop {
        // do something, like get a TcpStream
        let stream = accept_next_connection();
        match stream {
            Some(Ok(s)) => pool.dispatch(Arc::new(s)),
            Some(Err(e)) => panic!(e),
            None => break,
        }
    }

    // Dropping the pool will send a Quit message to all active threads
    and detach them. No joins happen here.
    drop(pool);
}