pub struct ThreadPool { /* private fields */ }
Expand description

A general-purpose thread pool for scheduling tasks that poll futures to completion.

The thread pool multiplexes any number of tasks onto a fixed number of worker threads.

This type is a clonable handle to the threadpool itself. Cloning it will only create a new reference, not a new threadpool.

This type is only available when the thread-pool feature of this library is activated.

Implementations§

source§

impl ThreadPool

source

pub fn new() -> Result<ThreadPool, Error>

Creates a new thread pool with the default configuration.

See documentation for the methods in ThreadPoolBuilder for details on the default configuration.

source

pub fn builder() -> ThreadPoolBuilder

Create a default thread pool configuration, which can then be customized.

See documentation for the methods in ThreadPoolBuilder for details on the default configuration.

source

pub fn spawn_obj_ok(&self, future: FutureObj<'static, ()>)

Spawns a future that will be run to completion.

Note: This method is similar to Spawn::spawn_obj, except that it is guaranteed to always succeed.

source

pub fn spawn_ok<Fut>(&self, future: Fut)where Fut: Future<Output = ()> + Send + 'static,

Spawns a task that polls the given future with output () to completion.

use futures::executor::ThreadPool;

let pool = ThreadPool::new().unwrap();

let future = async { /* ... */ };
pool.spawn_ok(future);

Note: This method is similar to SpawnExt::spawn, except that it is guaranteed to always succeed.

Trait Implementations§

source§

impl Clone for ThreadPool

source§

fn clone(&self) -> ThreadPool

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ThreadPool

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Drop for ThreadPool

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Spawn for ThreadPool

source§

fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError>

Spawns a future that will be run to completion. Read more
source§

fn status(&self) -> Result<(), SpawnError>

Determines whether the executor is able to spawn new tasks. Read more
source§

impl<Out: 'static + Send> SpawnHandle<Out> for ThreadPool

source§

fn spawn_handle_obj( &self, future: FutureObj<'static, Out> ) -> Result<JoinHandle<Out>, SpawnError>

Spawn a future and return a JoinHandle that can be awaited for the output of the future.
source§

impl Timer for ThreadPool

Available on crate features timer and async_global only.
source§

fn sleep(&self, dur: Duration) -> BoxFuture<'static, ()>

Future that resolves after a given duration.
source§

impl YieldNow for ThreadPool

source§

fn yield_now(&self) -> YieldNowFut

Await this future in order to yield to the executor.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<Sp> SpawnExt for Spwhere Sp: Spawn + ?Sized,

source§

fn spawn<Fut>(&self, future: Fut) -> Result<(), SpawnError>where Fut: Future<Output = ()> + Send + 'static,

Spawns a task that polls the given future with output () to completion. Read more
source§

fn spawn_with_handle<Fut>( &self, future: Fut ) -> Result<RemoteHandle<<Fut as Future>::Output>, SpawnError>where Fut: Future + Send + 'static, <Fut as Future>::Output: Send,

Spawns a task that polls the given future to completion and returns a future that resolves to the spawned future’s output. Read more
source§

impl<T, Out> SpawnHandleExt<Out> for Twhere T: SpawnHandle<Out> + ?Sized, Out: 'static + Send,

source§

fn spawn_handle( &self, future: impl Future<Output = Out> + Send + 'static ) -> Result<JoinHandle<Out>, SpawnError>

Spawn a future and return a JoinHandle that can be awaited for the output of the future.
source§

impl<T> TimerExt for Twhere T: Timer,

source§

fn timeout<F: Future>(&self, duration: Duration, future: F) -> Timeout<F>

Wrap a Future with a timeout. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more