20 releases

Uses old Rust 2015

0.7.1 Dec 6, 2017
0.6.4 Sep 27, 2017
0.6.2 Apr 24, 2017
0.6.1 Mar 10, 2017
0.2.0 Dec 31, 2016

#321 in Concurrency

Download history 21/week @ 2020-05-22 21/week @ 2020-05-29 43/week @ 2020-06-05 1/week @ 2020-06-26 42/week @ 2020-07-03 42/week @ 2020-07-10 22/week @ 2020-07-17 1/week @ 2020-07-31 42/week @ 2020-08-07 1/week @ 2020-08-14 22/week @ 2020-08-21 21/week @ 2020-08-28 62/week @ 2020-09-04

172 downloads per month

MIT license

30KB
719 lines

Build status Latest version All downloads Downloads of latest version Documentation

poolite

A lite threadpool library written for Rust.

Usage

On Cargo.toml:

 [dependencies]
 poolite = "0.7.1"

Documentation

or

  • Run cargo doc --open after modified the toml file.

Base usage

extern crate poolite;
use poolite::Pool;

fn main() {
    let pool = Pool::new().unwrap();
    for i in 0..38 {
        pool.push(move || test(i));
    }

    pool.join(); //wait for the pool
}

fn test(msg: i32) {
    println!("key: {}\tvalue: {}", msg, fib(msg));
}

fn fib(msg: i32) -> i32 {
    match msg {
        0...2 => 1,
        x => fib(x - 1) + fib(x - 2),
    }
}

Scoped Task

extern crate poolite;
use poolite::Pool;

fn main() {
    let pool = Pool::new().unwrap();
    let mut array = (0..100usize).into_iter().map(|i| (i, 0)).collect::<Vec<_>>();

    // scoped method will waiting scoped's task running finish.
    pool.scoped(|scope| for i in array.iter_mut() {
        // have to move
        scope.push(move|| i.1 = i.0*i.0);
    });

    for (i, j) in array {
        println!("key: {}\tvalue: {}", i, j);
    }
}

More Examples..

Dependencies

~4MB
~96K SLoC