Priority Multi Consumer Multi Producer Channel
This is a quick and dirty implementation of a multi producer multi consumer channel for elements that implement the Ord trait, which gives the user two methods on the receiver: recvgreatest and recvleast.
```rust use pmpmc::pmpmc; let (tx, rx) = pmpmc();
let txnew = tx.clone(); let rxnew = rx.clone();
let _ = std::thread::spawn(move || { txnew.send(2); txnew.send(1); tx_new.send(3); }) .join();
asserteq!(rxnew.recvgreatest(), Some(3)); asserteq!(rxnew.recvgreatest(), Some(2)); asserteq!(rxnew.recvgreatest(), Some(1)); asserteq!(rxnew.recvgreatest(), None); asserteq!(rxnew.recv_greatest(), None);
let txnew = tx.clone(); let rxnew = rx.clone();
let _ = std::thread::spawn(move || { txnew.send(2); txnew.send(1); tx_new.send(3); }) .join();
asserteq!(rxnew.recvleast(), Some(1)); asserteq!(rxnew.recvleast(), Some(2)); asserteq!(rxnew.recvleast(), Some(3)); asserteq!(rxnew.recvleast(), None); asserteq!(rxnew.recv_least(), None); ```
I am using it for automatically scheduling tasks (workers now pull tasks off the channel in order of priority) but you can use it any time you want to push to a list from one or more threads and sort the list before receiving on another thread.
This crate is not optimized in any way, please don't use it in production. When I have time I may come back and make it more efficient and robust.
License: MIT