#futures #thread #computation

futures-cpupool

An implementation of thread pools which hand out futures to the results of the computation on the threads themselves

8 releases

0.1.8 Jan 2, 2018
0.1.7 Oct 12, 2017
0.1.6 Sep 14, 2017
0.1.5 Mar 21, 2017
0.1.0 Aug 1, 2016
Download history 63481/week @ 2020-02-09 57160/week @ 2020-02-16 54940/week @ 2020-02-23 57535/week @ 2020-03-01 58640/week @ 2020-03-08 56485/week @ 2020-03-15 58918/week @ 2020-03-22 59883/week @ 2020-03-29 59876/week @ 2020-04-05 57440/week @ 2020-04-12 64733/week @ 2020-04-19 60920/week @ 2020-04-26 55581/week @ 2020-05-03 69305/week @ 2020-05-10 66978/week @ 2020-05-17 66006/week @ 2020-05-24

249,113 downloads per month
Used in less than 93 crates

MIT/Apache

17KB
248 lines

futures-cpupool

A library for creating futures representing work happening concurrently on a dedicated thread pool.

Build Status Build status

Documentation

Usage

First, add this to your Cargo.toml:

[dependencies]
futures = "0.1"
futures-cpupool = "0.1"

Next, add this to your crate:

extern crate futures;
extern crate futures_cpupool;

use futures_cpupool::CpuPool;

License

futures-cpupool is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), with portions covered by various BSD-like licenses.

See LICENSE-APACHE, and LICENSE-MIT for details.


lib.rs:

A simple crate for executing work on a thread pool, and getting back a future.

This crate provides a simple thread pool abstraction for running work externally from the current thread that's running. An instance of Future is handed back to represent that the work may be done later, and further computations can be chained along with it as well.

extern crate futures;
extern crate futures_cpupool;

use futures::Future;
use futures_cpupool::CpuPool;

# fn long_running_future(a: u32) -> Box<futures::future::Future<Item = u32, Error = ()> + Send> {
#     Box::new(futures::future::result(Ok(a)))
# }
# fn main() {

// Create a worker thread pool with four threads
let pool = CpuPool::new(4);

// Execute some work on the thread pool, optionally closing over data.
let a = pool.spawn(long_running_future(2));
let b = pool.spawn(long_running_future(100));

// Express some further computation once the work is completed on the thread
// pool.
let c = a.join(b).map(|(a, b)| a + b).wait().unwrap();

// Print out the result
println!("{:?}", c);
# }

Dependencies

~91KB