[][src]Struct workerpool::Builder

pub struct Builder { /* fields omitted */ }

Pool factory, which can be used in order to configure the properties of the Pool.

The three configuration options available:

  • num_threads: maximum number of threads that will be alive at any given moment by the built Pool
  • thread_name: thread name for each of the threads spawned by the built Pool
  • thread_stack_size: stack size (in bytes) for each of the threads spawned by the built Pool

Examples

Build a Pool that uses a maximum of eight threads simultaneously and each thread has a 8 MB stack size:

let pool = workerpool::Builder::new()
    .num_threads(8)
    .thread_stack_size(8_000_000)
    .build::<MyWorker>();

Methods

impl Builder[src]

pub fn new() -> Builder[src]

Initiate a new Builder.

Examples

let builder = workerpool::Builder::new();

pub fn num_threads(self, num_threads: usize) -> Builder[src]

Set the maximum number of worker-threads that will be alive at any given moment by the built Pool. If not specified, defaults the number of threads to the number of CPUs.

Panics

This method will panic if num_threads is 0.

Examples

No more than eight threads will be alive simultaneously for this pool:

use std::thread;
use workerpool::{Builder, Pool};
use workerpool::thunk::{Thunk, ThunkWorker};

let pool: Pool<ThunkWorker<()>> = Builder::new()
    .num_threads(8)
    .build();

for _ in 0..100 {
    pool.execute(Thunk::of(|| {
        println!("Hello from a worker thread!")
    }))
}

pub fn thread_name(self, name: String) -> Builder[src]

Set the thread name for each of the threads spawned by the built Pool. If not specified, threads spawned by the thread pool will be unnamed.

Examples

Each thread spawned by this pool will have the name "foo":

use std::thread;
use workerpool::{Builder, Pool};
use workerpool::thunk::{Thunk, ThunkWorker};

let pool: Pool<ThunkWorker<()>> = Builder::new()
    .thread_name("foo".into())
    .build();

for _ in 0..100 {
    pool.execute(Thunk::of(|| {
        assert_eq!(thread::current().name(), Some("foo"));
    }))
}

pub fn thread_stack_size(self, size: usize) -> Builder[src]

Set the stack size (in bytes) for each of the threads spawned by the built Pool. If not specified, threads spawned by the workerpool will have a stack size as specified in the std::thread documentation.

Examples

Each thread spawned by this pool will have a 4 MB stack:

let pool: Pool<ThunkWorker<()>> = Builder::new()
    .thread_stack_size(4_000_000)
    .build();

for _ in 0..100 {
    pool.execute(Thunk::of(|| {
        println!("This thread has a 4 MB stack size!");
    }))
}

pub fn build<T>(self) -> Pool<T> where
    T: Worker
[src]

Finalize the Builder and build the Pool.

Examples

use workerpool::{Builder, Pool};
let pool: Pool<MyWorker> = Builder::new()
    .num_threads(8)
    .thread_stack_size(4_000_000)
    .build();

Trait Implementations

impl Default for Builder[src]

impl Clone for Builder[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl Send for Builder

impl Sync for Builder

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Erased for T