https://github.com/jcbritobr/workerpool
A simple workerpool implementation in rust.
https://github.com/jcbritobr/workerpool
parallel rust threading worker-pool
Last synced: 11 months ago
JSON representation
A simple workerpool implementation in rust.
- Host: GitHub
- URL: https://github.com/jcbritobr/workerpool
- Owner: jcbritobr
- License: mit
- Created: 2020-09-24T22:55:31.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-05-05T17:40:56.000Z (almost 3 years ago)
- Last Synced: 2025-03-28T02:21:33.713Z (12 months ago)
- Topics: parallel, rust, threading, worker-pool
- Language: Rust
- Homepage:
- Size: 22.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Workerpool
A simple rust workerpool implementation that uses channels to synchronize the jobs. It can spawn a fixed number of worker threads, that waits for a job queue to consum.
* Use
```rust
use workerpool_rs::pool::WorkerPool;
use std::sync::mpsc::channel;
use std::sync::{Arc, Mutex};
let n_workers = 4;
let n_jobs = 8;
let pool = WorkerPool::new(n_workers);
let (tx, rx) = channel();
let atx = Arc::new(Mutex::new(tx));
for _ in 0..n_jobs {
let atx = atx.clone();
pool.execute(move|| {
let tx = atx.lock().unwrap();
tx.send(1).expect("channel will be there waiting for the pool");
});
}
assert_eq!(rx.iter().take(n_jobs).fold(0, |a, b| a + b), 8);
```
* Test
```shell
$ cargo test
```