poolite

Crates.iopoolite
lib.rspoolite
version0.7.1
sourcesrc
created_at2016-12-31 17:36:41.184507
updated_at2017-12-06 12:32:53.572191
descriptionA lite threadpool library.
homepage
repositoryhttps://github.com/biluohc/poolite
max_upload_size
id7874
size38,371
wspsxing (biluohc)

documentation

https://docs.rs/poolite/

README

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..

Commit count: 49

cargo fmt