pub struct Pool { /* private fields */ }Expand description
The Pool struct
Implementations§
Source§impl Pool
impl Pool
Sourcepub fn new() -> Result<Self, PoolError>
pub fn new() -> Result<Self, PoolError>
Examples found in repository?
More examples
examples/into.rs (line 12)
11fn into_inner() {
12 let pool = match Pool::new() {
13 Ok(p) => p,
14 Err(e) => e.into_inner(),
15 };
16 for i in 0..38 {
17 pool.push(move || test(i));
18 }
19
20 pool.join(); //wait for the pool
21}
22
23fn into_error() -> io::Result<()> {
24 let pool = Pool::new().map_err(|e| e.into_error())?;
25 for i in 0..38 {
26 pool.push(move || test(i));
27 }
28
29 pool.join(); //wait for the pool
30
31 Ok(())
32}examples/channel.rs (line 8)
7fn main() {
8 let pool = Pool::new().unwrap();
9 let (mp, sc) = channel();
10 for i in 0..38 {
11 let mp = mp.clone();
12 pool.push(move || test(i, mp));
13 }
14
15 pool.join(); // wait for the pool
16 println!("{:?}", pool);
17
18 while let Ok((k, v)) = sc.try_recv() {
19 println!("key: {}\tvalue: {}", k, v);
20 }
21}examples/arc_mutex.rs (line 9)
8fn main() {
9 let pool = Pool::new().unwrap();
10 // You also can use RwLock instead of Mutex if you read more than write.
11 let map = Arc::new(Mutex::new(BTreeMap::<i32, i32>::new()));
12 for i in 0..38 {
13 let map = map.clone();
14 pool.push(move || test(i, map));
15 }
16
17 pool.join(); //wait for the pool
18
19 for (k, v) in map.lock().unwrap().iter() {
20 println!("key: {}\tvalue: {}", k, v);
21 }
22}pub fn with_builder(b: Builder) -> Result<Self, PoolError>
Sourcepub fn as_builder(&self) -> &Builder
pub fn as_builder(&self) -> &Builder
Get Pool’s settings
Sourcepub fn threads_future(&self) -> usize
pub fn threads_future(&self) -> usize
Contains the number of ready to create
Sourcepub fn threads_alive(&self) -> usize
pub fn threads_alive(&self) -> usize
Returns the number of threads in the Pool.
Sourcepub fn threads_waiting(&self) -> usize
pub fn threads_waiting(&self) -> usize
Returns the number of threads that is waiting for Task in the Pool
Sourcepub fn daemon_alive(&self) -> bool
pub fn daemon_alive(&self) -> bool
The daemon thread’s status
Sourcepub fn push<T>(&self, task: T)
pub fn push<T>(&self, task: T)
Appends a task to the Pool,
it receives Fn() + Send + 'static,FnMut() + Send + 'static and FnOnce() + Send + 'static>.
Examples found in repository?
More examples
examples/into.rs (line 17)
11fn into_inner() {
12 let pool = match Pool::new() {
13 Ok(p) => p,
14 Err(e) => e.into_inner(),
15 };
16 for i in 0..38 {
17 pool.push(move || test(i));
18 }
19
20 pool.join(); //wait for the pool
21}
22
23fn into_error() -> io::Result<()> {
24 let pool = Pool::new().map_err(|e| e.into_error())?;
25 for i in 0..38 {
26 pool.push(move || test(i));
27 }
28
29 pool.join(); //wait for the pool
30
31 Ok(())
32}examples/builder.rs (line 17)
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}examples/channel.rs (line 12)
7fn main() {
8 let pool = Pool::new().unwrap();
9 let (mp, sc) = channel();
10 for i in 0..38 {
11 let mp = mp.clone();
12 pool.push(move || test(i, mp));
13 }
14
15 pool.join(); // wait for the pool
16 println!("{:?}", pool);
17
18 while let Ok((k, v)) = sc.try_recv() {
19 println!("key: {}\tvalue: {}", k, v);
20 }
21}examples/arc_mutex.rs (line 14)
8fn main() {
9 let pool = Pool::new().unwrap();
10 // You also can use RwLock instead of Mutex if you read more than write.
11 let map = Arc::new(Mutex::new(BTreeMap::<i32, i32>::new()));
12 for i in 0..38 {
13 let map = map.clone();
14 pool.push(move || test(i, map));
15 }
16
17 pool.join(); //wait for the pool
18
19 for (k, v) in map.lock().unwrap().iter() {
20 println!("key: {}\tvalue: {}", k, v);
21 }
22}Sourcepub fn add_threads(&self, add_num: usize) -> Result<(), (usize, Error)>
pub fn add_threads(&self, add_num: usize) -> Result<(), (usize, Error)>
Manually add the number of threads to Pool
Sourcepub fn join(&self)
pub fn join(&self)
wait for the pool
Examples found in repository?
More examples
examples/into.rs (line 20)
11fn into_inner() {
12 let pool = match Pool::new() {
13 Ok(p) => p,
14 Err(e) => e.into_inner(),
15 };
16 for i in 0..38 {
17 pool.push(move || test(i));
18 }
19
20 pool.join(); //wait for the pool
21}
22
23fn into_error() -> io::Result<()> {
24 let pool = Pool::new().map_err(|e| e.into_error())?;
25 for i in 0..38 {
26 pool.push(move || test(i));
27 }
28
29 pool.join(); //wait for the pool
30
31 Ok(())
32}examples/builder.rs (line 20)
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}examples/channel.rs (line 15)
7fn main() {
8 let pool = Pool::new().unwrap();
9 let (mp, sc) = channel();
10 for i in 0..38 {
11 let mp = mp.clone();
12 pool.push(move || test(i, mp));
13 }
14
15 pool.join(); // wait for the pool
16 println!("{:?}", pool);
17
18 while let Ok((k, v)) = sc.try_recv() {
19 println!("key: {}\tvalue: {}", k, v);
20 }
21}examples/arc_mutex.rs (line 17)
8fn main() {
9 let pool = Pool::new().unwrap();
10 // You also can use RwLock instead of Mutex if you read more than write.
11 let map = Arc::new(Mutex::new(BTreeMap::<i32, i32>::new()));
12 for i in 0..38 {
13 let map = map.clone();
14 pool.push(move || test(i, map));
15 }
16
17 pool.join(); //wait for the pool
18
19 for (k, v) in map.lock().unwrap().iter() {
20 println!("key: {}\tvalue: {}", k, v);
21 }
22}Trait Implementations§
Auto Trait Implementations§
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