Struct poolite::Pool [] [src]

pub struct Pool { /* fields omitted */ }

The Pool struct.

Methods

impl Pool
[src]

Creating and Settings

The memory loading depends your task's costing,

get_min()(idle time) and get_max()(when received large number tasks).

Creates and returns a Pool.

Returns the number of CPUs of the current machine.

You can use it on min() ,max() or load_limit().

Maybe you also need std::usize::MIN or std::usize::MAX.

Sets whether to open the daemon for the Pool, the default is Some(5000)(thread's default idle time(ms)).

You can use None to close.

Warning: If you tasks maybe panic,please don't close it.

Returns the value of daemon()(Option<Duration>).

Sets the minimum number of threads in the Pool,default is num_cpus()+1.

Returns the value of the minimum number of threads in the Pool.

Sets the maximum number of threads in the Pool,default is std::usize::MAX.

Warning: even if get_min()>get_max(),the run() method still working well.

Returns the value of the maximum number of threads in the Pool.

Sets thread's idle time(ms) except minimum number of threads,default is 5000(ms).

Returns the value of the thread's idle time(Duration).

Sets thread's name where them in the Pool,default is None('<unnamed>').

Returns thread's name.

Sets thread's stack_size where them in the Pool,default depends on OS.

Returns thread's stack_size.

Sets the value of load_limit for the Pool,

The pool will create new thread while strong_count() == 0 or tasks_queue_len()/strong_count() bigger than it,

default is num_cpus() * num_cpus().

Returns the value of load_limit.

Complete Example for Creating and Settings:

extern crate poolite;
use poolite::Pool;

fn main() {
let pool = Pool::new()
    .daemon(Some(5000))
    .min(Pool::num_cpus() + 1)
    .max(std::usize::MAX)
    .time_out(5000) //5000ms
    .name("name")
    .stack_size(2 * 1024 * 1024) //2MiB
    .load_limit(Pool::num_cpus() * Pool::num_cpus())
    .run()
    .unwrap();
}

impl Pool
[src]

Lets the Pool to start running:

  • Add the number of min threads to the pool.

  • Add the daemon thread for the pool(if dont't close it).

    returns Err<PoolError> if the pool spawning the daemon thread fails.

    So if you close the daemon,unwrap() is safe.

    You maybe need IntoPool or IntoIOResult(trait).

    extern crate poolite;
    use poolite::{Pool, IntoPool, IntoIOResult};
    
    fn fun() -> std::io::Result<()> {
     let pool = Pool::new().run().into_pool();
     let pool_io_rst = Pool::new().run().into_iorst()?;
     let pool_nodaemon = Pool::new().daemon(None).unwrap();
     Ok(())
    }
    

Appends a task to the Pool,

it receives Fn() + Send + 'static,FnMut() + Send + 'static and

FnOnce() + Send + 'static>.

Deprecated since 0.6.0

: You should use push instead

it receives Box<Fn() + Send + 'static>,Box<FnMut() + Send + 'static> and

Box<FnOnce() + Send + 'static>(Box<FnBox() + Send + 'static>).

Manually add threads(Do not need to use it generally).

impl Pool
[src]

All threads are waiting and tasks_queue'length is 0.

Use it to wait for the Pool,you can also group is_empty() by yourself.

pub fn join(&self) {
         self.join_ms(10); //wait for the pool 10ms
    }

pub fn join_ms(&self, time: u64) {
       while !self.is_empty() {
           thread::sleep(Duration::from_millis(time)); //wait for the pool time(ms).
       }
    }

Returns the length of the tasks_queue.

Warning: tasks_len() will get the lock, please do not abuse it(Affecting performance).

Approximately equal to len().

Returns the thread'number in the Pool.

Returns the thread'number that is waiting in the Pool

Trait Implementations

impl Drop for Pool
[src]

A method called when the value goes out of scope. Read more

impl Default for Pool
[src]

Returns the "default value" for a type. Read more