Struct futures_cpupool::CpuPool [] [src]

pub struct CpuPool { /* fields omitted */ }

A thread pool intended to run CPU intensive work.

This thread pool will hand out futures representing the completed work that happens on the thread pool itself, and the futures can then be later composed with other work as part of an overall computation.

The worker threads associated with a thread pool are kept alive so long as there is an open handle to the CpuPool or there is work running on them. Once all work has been drained and all references have gone away the worker threads will be shut down.

Currently CpuPool implements Clone which just clones a new reference to the underlying thread pool.

Note: if you use CpuPool inside a library it's better accept a Builder object for thread configuration rather than configuring just pool size. This not only future proof for other settings but also allows user to attach monitoring tools to lifecycle hooks.


impl CpuPool

Creates a new thread pool with size worker threads associated with it.

The returned handle can use execute to run work on this thread pool, and clones can be made of it to get multiple references to the same thread pool.

This is a shortcut for: rust Builder::new().pool_size(size).create()


Panics if size == 0.

Creates a new thread pool with a number of workers equal to the number of CPUs on the host.

This is a shortcut for: rust Builder::new().create()

Spawns a future to run on this thread pool, returning a future representing the produced value.

This function will execute the future f on the associated thread pool, and return a future representing the finished computation. The returned future serves as a proxy to the computation that F is running.

To simply run an arbitrary closure on a thread pool and extract the result, you can use the future::lazy combinator to defer work to executing on the thread pool itself.

Note that if the future f panics it will be caught by default and the returned future will propagate the panic. That is, panics will not tear down the thread pool and will be propagated to the returned future's poll method if queried.

If the returned future is dropped then this CpuPool will attempt to cancel the computation, if possible. That is, if the computation is in the middle of working, it will be interrupted when possible.

Spawns a closure on this thread pool.

This function is a convenience wrapper around the spawn function above for running a closure wrapped in future::lazy. It will spawn the function f provided onto the thread pool, and continue to run the future returned by f on the thread pool as well.

The returned future will be a handle to the result produced by the future that f returns.

Trait Implementations

impl Clone for CpuPool

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Drop for CpuPool

A method called when the value goes out of scope. Read more