[−][src]Struct futures_cpupool::CpuPool
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.
Methods
impl CpuPool
[src]
pub fn new(size: usize) -> CpuPool
[src]
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:
Builder::new().pool_size(size).create()
Panics
Panics if size == 0
.
pub fn new_num_cpus() -> CpuPool
[src]
Creates a new thread pool with a number of workers equal to the number of CPUs on the host.
This is a shortcut for:
Builder::new().create()
pub fn spawn<F>(&self, f: F) -> CpuFuture<F::Item, F::Error> where
F: Future + Send + 'static,
F::Item: Send + 'static,
F::Error: Send + 'static,
[src]
F: Future + Send + 'static,
F::Item: Send + 'static,
F::Error: Send + 'static,
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.
pub fn spawn_fn<F, R>(&self, f: F) -> CpuFuture<R::Item, R::Error> where
F: FnOnce() -> R + Send + 'static,
R: IntoFuture + 'static,
R::Future: Send + 'static,
R::Item: Send + 'static,
R::Error: Send + 'static,
[src]
F: FnOnce() -> R + Send + 'static,
R: IntoFuture + 'static,
R::Future: Send + 'static,
R::Item: Send + 'static,
R::Error: Send + 'static,
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 Drop for CpuPool
[src]
impl Clone for CpuPool
[src]
impl Debug for CpuPool
[src]
impl<F> Executor<F> for CpuPool where
F: Future<Item = (), Error = ()> + Send + 'static,
[src]
F: Future<Item = (), Error = ()> + Send + 'static,
fn execute(&self, future: F) -> Result<(), ExecuteError<F>>
[src]
Auto Trait Implementations
impl Send for CpuPool
impl Unpin for CpuPool
impl Sync for CpuPool
impl UnwindSafe for CpuPool
impl RefUnwindSafe for CpuPool
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,