Struct ThreadPoolBuilder

Source
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()
        .with_name_str("example")
        .with_tasks(4)
        .with_queue_size(16)
        .with_shutdown_mode(ShutdownMode::CompletePending)
        .build()
}
Source

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

Set the base name for threads in the thread pool

Source

pub fn with_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 with_tasks(&mut self, tasks: usize) -> &mut ThreadPoolBuilder

Set the number of threads in the thread pool

Source

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

Specify the ShutdownMode

Source

pub fn with_queue_type( &mut self, queue_type: QueueType, ) -> &mut ThreadPoolBuilder

Specify the QueueType

Source

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

Specify the queue size for the thread pool

Source

pub fn with_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

Trait Implementations§

Source§

impl Default for ThreadPoolBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.