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

Build a ThreadPool

Modify default thread pool parameters and build the thread pool

Implementations§

source§

impl ThreadPoolBuilder

source

pub fn new() -> ThreadPoolBuilder

Create a new builder

Default values:

  • name - “unnamed”
  • tasks - 1
  • queue_size - 16
  • join_error_handler - a simple panicking error handler
  • shutdown_mode - ShutdownMode::Immediate
Example

use command_executor::shutdown_mode::ShutdownMode;
use command_executor::thread_pool::ThreadPool;
use command_executor::thread_pool_builder::ThreadPoolBuilder;

fn create_thread_pool() -> Result<ThreadPool, anyhow::Error> {
    ThreadPoolBuilder::new()
        .name_str("example")
        .tasks(4)
        .queue_size(16)
        .shutdown_mode(ShutdownMode::CompletePending)
        .build()
}
source

pub fn name(&mut self, name: String) -> &mut ThreadPoolBuilder

Set the base name for threads in the thread pool

source

pub fn name_str(&mut self, name: &str) -> &mut ThreadPoolBuilder

Set the base name for threads in the thread pool. A convenience method that accepts &str

source

pub fn tasks(&mut self, tasks: usize) -> &mut ThreadPoolBuilder

Set the number of threads in the thread pool

source

pub fn shutdown_mode( &mut self, shutdown_mode: ShutdownMode ) -> &mut ThreadPoolBuilder

Specify the ShutdownMode

source

pub fn queue_size(&mut self, queue_size: usize) -> &mut ThreadPoolBuilder

Specify the queue size for the thread pool

source

pub fn join_error_handler( &mut self, join_error_handler: fn(_: String, _: String) ) -> &mut ThreadPoolBuilder

Set the error handler that is called for each thread that exited with error during join

source

pub fn build(&self) -> Result<ThreadPool, Error>

Build the thread pool

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, 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.

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.