pub struct Builder { /* private fields */ }Expand description
Pool’s Settings
extern crate poolite;
use poolite::Builder;
/// `cargo run --example without`
fn main() {
let pool = Builder::new()
.min(2)
.max(9)
.daemon(None) // Close daemon
.timeout(None) // Close timeout
.name("Worker")
.stack_size(1024*1024*2) //2Mib
.build()
.unwrap();
for i in 0..33 {
pool.push(move || test(i));
}
pool.join(); //wait for the pool
println!("{:?}", pool);
}
fn test(msg: i32) {
println!("key: {}\tvalue: {}", msg, fib(msg));
}
fn fib(msg: i32) -> i32 {
match msg {
0...2 => 1,
x => fib(x - 1) + fib(x - 2),
}
}Implementations§
Source§impl Builder
impl Builder
pub fn num_cpus() -> usize
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/builder.rs (line 6)
5fn main() {
6 let pool = Builder::new()
7 .min(1)
8 .max(9)
9 .daemon(None) // Close
10 .timeout(None) //Close
11 .name("Worker")
12 .stack_size(1024*1024*2) //2Mib
13 .build()
14 .unwrap();
15
16 for i in 0..38 {
17 pool.push(move || test(i));
18 }
19
20 pool.join(); //wait for the pool
21 println!("{:?}", pool);
22}Sourcepub fn name<S>(self, name: S) -> Self
pub fn name<S>(self, name: S) -> Self
Sets thread’s name where them in the Pool,default is None('<unnamed>').
Examples found in repository?
examples/builder.rs (line 11)
5fn main() {
6 let pool = Builder::new()
7 .min(1)
8 .max(9)
9 .daemon(None) // Close
10 .timeout(None) //Close
11 .name("Worker")
12 .stack_size(1024*1024*2) //2Mib
13 .build()
14 .unwrap();
15
16 for i in 0..38 {
17 pool.push(move || test(i));
18 }
19
20 pool.join(); //wait for the pool
21 println!("{:?}", pool);
22}pub fn name_get(&self) -> Option<&String>
Sourcepub fn stack_size(self, size: usize) -> Self
pub fn stack_size(self, size: usize) -> Self
Sets thread’s stack_size where them in the Pool,default depends on OS.
Examples found in repository?
examples/builder.rs (line 12)
5fn main() {
6 let pool = Builder::new()
7 .min(1)
8 .max(9)
9 .daemon(None) // Close
10 .timeout(None) //Close
11 .name("Worker")
12 .stack_size(1024*1024*2) //2Mib
13 .build()
14 .unwrap();
15
16 for i in 0..38 {
17 pool.push(move || test(i));
18 }
19
20 pool.join(); //wait for the pool
21 println!("{:?}", pool);
22}pub fn stack_size_get(&self) -> Option<&usize>
Sourcepub fn min(self, min: usize) -> Self
pub fn min(self, min: usize) -> Self
Sets the minimum number of threads in the Pool,default is num_cpus()+1.
Examples found in repository?
examples/builder.rs (line 7)
5fn main() {
6 let pool = Builder::new()
7 .min(1)
8 .max(9)
9 .daemon(None) // Close
10 .timeout(None) //Close
11 .name("Worker")
12 .stack_size(1024*1024*2) //2Mib
13 .build()
14 .unwrap();
15
16 for i in 0..38 {
17 pool.push(move || test(i));
18 }
19
20 pool.join(); //wait for the pool
21 println!("{:?}", pool);
22}pub fn min_get(&self) -> &usize
Sourcepub fn max(self, max: usize) -> Self
pub fn max(self, max: usize) -> Self
Sets the maximum number of threads in the Pool,default is (num_cpus()+1)*num_cpus().
Examples found in repository?
examples/builder.rs (line 8)
5fn main() {
6 let pool = Builder::new()
7 .min(1)
8 .max(9)
9 .daemon(None) // Close
10 .timeout(None) //Close
11 .name("Worker")
12 .stack_size(1024*1024*2) //2Mib
13 .build()
14 .unwrap();
15
16 for i in 0..38 {
17 pool.push(move || test(i));
18 }
19
20 pool.join(); //wait for the pool
21 println!("{:?}", pool);
22}pub fn max_get(&self) -> &usize
Sourcepub fn timeout_ms(self, timeout: Option<u64>) -> Self
pub fn timeout_ms(self, timeout: Option<u64>) -> Self
Sets thread’s idle time(ms) except minimum number of threads,default is 5000(ms).
Sourcepub fn timeout(self, timeout: Option<Duration>) -> Self
pub fn timeout(self, timeout: Option<Duration>) -> Self
Examples found in repository?
examples/builder.rs (line 10)
5fn main() {
6 let pool = Builder::new()
7 .min(1)
8 .max(9)
9 .daemon(None) // Close
10 .timeout(None) //Close
11 .name("Worker")
12 .stack_size(1024*1024*2) //2Mib
13 .build()
14 .unwrap();
15
16 for i in 0..38 {
17 pool.push(move || test(i));
18 }
19
20 pool.join(); //wait for the pool
21 println!("{:?}", pool);
22}pub fn timeout_get(&self) -> Option<&Duration>
Sourcepub fn daemon_ms(self, daemon: Option<u64>) -> Self
pub fn daemon_ms(self, daemon: Option<u64>) -> Self
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.
Sourcepub fn daemon(self, daemon: Option<Duration>) -> Self
pub fn daemon(self, daemon: Option<Duration>) -> Self
Examples found in repository?
examples/builder.rs (line 9)
5fn main() {
6 let pool = Builder::new()
7 .min(1)
8 .max(9)
9 .daemon(None) // Close
10 .timeout(None) //Close
11 .name("Worker")
12 .stack_size(1024*1024*2) //2Mib
13 .build()
14 .unwrap();
15
16 for i in 0..38 {
17 pool.push(move || test(i));
18 }
19
20 pool.join(); //wait for the pool
21 println!("{:?}", pool);
22}pub fn daemon_get(&self) -> Option<&Duration>
Sourcepub fn load_limit(self, load_limit: usize) -> Self
pub fn load_limit(self, load_limit: usize) -> Self
Sets the value of load_limit for the Pool.
default is num_cpus() * num_cpus().
pub fn load_limit_get(&self) -> &usize
Sourcepub fn build(self) -> Result<Pool, PoolError>
pub fn build(self) -> Result<Pool, PoolError>
Examples found in repository?
examples/builder.rs (line 13)
5fn main() {
6 let pool = Builder::new()
7 .min(1)
8 .max(9)
9 .daemon(None) // Close
10 .timeout(None) //Close
11 .name("Worker")
12 .stack_size(1024*1024*2) //2Mib
13 .build()
14 .unwrap();
15
16 for i in 0..38 {
17 pool.push(move || test(i));
18 }
19
20 pool.join(); //wait for the pool
21 println!("{:?}", pool);
22}Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Builder
impl !RefUnwindSafe for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin for Builder
impl !UnwindSafe for Builder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more