[−][src]Struct tokio_threadpool::ThreadPool
Work-stealing based thread pool for executing futures.
If a ThreadPool instance is dropped without explicitly being shutdown,
shutdown_now is called implicitly, forcing all tasks that have not yet
completed to be dropped.
Create ThreadPool instances using Builder.
Methods
impl ThreadPool[src]
impl ThreadPoolpub fn new() -> ThreadPool[src]
pub fn new() -> ThreadPoolCreate a new ThreadPool with default values.
Use Builder for creating a configured thread pool.
pub fn spawn<F>(&self, future: F) where
F: Future<Item = (), Error = ()> + Send + 'static, [src]
pub fn spawn<F>(&self, future: F) where
F: Future<Item = (), Error = ()> + Send + 'static, Spawn a future onto the thread pool.
This function takes ownership of the future and randomly assigns it to a worker thread. The thread will then start executing the future.
Examples
use futures::future::{Future, lazy}; // Create a thread pool with default configuration values let thread_pool = ThreadPool::new(); thread_pool.spawn(lazy(|| { println!("called from a worker thread"); Ok(()) })); // Gracefully shutdown the threadpool thread_pool.shutdown().wait().unwrap();
Panics
This function panics if the spawn fails. Use [Sender::spawn] for a
version that returns a Result instead of panicking.
pub fn spawn_handle<F>(&self, future: F) -> SpawnHandle<F::Item, F::Error> where
F: Future + Send + 'static,
F::Item: Send + 'static,
F::Error: Send + 'static, [src]
pub fn spawn_handle<F>(&self, future: F) -> SpawnHandle<F::Item, F::Error> where
F: Future + Send + 'static,
F::Item: Send + 'static,
F::Error: Send + 'static, Spawn a future on to the thread pool, return a future representing the produced value.
The SpawnHandle returned is a future that is a proxy for future itself. When future completes on this thread pool then the SpawnHandle will itself be resolved.
Examples
use futures::future::{Future, lazy}; // Create a thread pool with default configuration values let thread_pool = ThreadPool::new(); let handle = thread_pool.spawn_handle(lazy(|| Ok::<_, ()>(42))); let value = handle.wait().unwrap(); assert_eq!(value, 42); // Gracefully shutdown the threadpool thread_pool.shutdown().wait().unwrap();
Panics
This function panics if the spawn fails.
pub fn sender(&self) -> &Sender[src]
pub fn sender(&self) -> &SenderReturn a reference to the sender handle
The handle is used to spawn futures onto the thread pool. It also
implements the Executor trait.
pub fn sender_mut(&mut self) -> &mut Sender[src]
pub fn sender_mut(&mut self) -> &mut SenderReturn a mutable reference to the sender handle
pub fn shutdown_on_idle(self) -> Shutdown[src]
pub fn shutdown_on_idle(self) -> ShutdownShutdown the pool once it becomes idle.
Idle is defined as the completion of all futures that have been spawned onto the thread pool. There may still be outstanding handles when the thread pool reaches an idle state.
Once the idle state is reached, calling spawn on any outstanding
handle will result in an error. All worker threads are signaled and will
shutdown. The returned future completes once all worker threads have
completed the shutdown process.
pub fn shutdown(self) -> Shutdown[src]
pub fn shutdown(self) -> ShutdownShutdown the pool
This prevents the thread pool from accepting new tasks but will allow any existing tasks to complete.
Calling spawn on any outstanding handle will result in an error. All
worker threads are signaled and will shutdown. The returned future
completes once all worker threads have completed the shutdown process.
pub fn shutdown_now(self) -> Shutdown[src]
pub fn shutdown_now(self) -> ShutdownShutdown the pool immediately
This will prevent the thread pool from accepting new tasks and abort any tasks that are currently running on the thread pool.
Calling spawn on any outstanding handle will result in an error. All
worker threads are signaled and will shutdown. The returned future
completes once all worker threads have completed the shutdown process.
Trait Implementations
impl Drop for ThreadPool[src]
impl Drop for ThreadPoolimpl Debug for ThreadPool[src]
impl Debug for ThreadPoolAuto Trait Implementations
impl Send for ThreadPool
impl Send for ThreadPoolimpl Sync for ThreadPool
impl Sync for ThreadPoolBlanket Implementations
impl<T> From for T[src]
impl<T> From for Timpl<T, U> Into for T where
U: From<T>, [src]
impl<T, U> Into for T where
U: From<T>, impl<T, U> TryFrom for T where
T: From<U>, [src]
impl<T, U> TryFrom for T where
T: From<U>, type Error = !
try_from)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>try_from)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized, [src]
impl<T> Borrow for T where
T: ?Sized, impl<T> BorrowMut for T where
T: ?Sized, [src]
impl<T> BorrowMut for T where
T: ?Sized, fn borrow_mut(&mut self) -> &mut T[src]
fn borrow_mut(&mut self) -> &mut TMutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>, [src]
impl<T, U> TryInto for T where
U: TryFrom<T>, type Error = <U as TryFrom<T>>::Error
try_from)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>try_from)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized, [src]
impl<T> Any for T where
T: 'static + ?Sized, fn get_type_id(&self) -> TypeId[src]
fn get_type_id(&self) -> TypeId🔬 This is a nightly-only experimental API. (get_type_id)
this method will likely be replaced by an associated static
Gets the TypeId of self. Read more