| Crates.io | tokio-mpmc |
| lib.rs | tokio-mpmc |
| version | 0.2.4 |
| created_at | 2025-05-19 23:08:52.848689+00 |
| updated_at | 2025-06-10 06:33:11.261059+00 |
| description | A multi-producer multi-consumer queue implementation based on Tokio |
| homepage | |
| repository | https://github.com/lispking/tokio-mpmc |
| max_upload_size | |
| id | 1680526 |
| size | 221,176 |
A high-performance multi-producer multi-consumer (MPMC) queue implementation based on Tokio.

Add the following dependency to your Cargo.toml:
[dependencies]
tokio-mpmc = "0.2"
use tokio_mpmc::Queue;
#[tokio::main]
async fn main() {
// Create a queue with capacity of 100
let queue = Queue::new(100);
// Send a message
if let Err(e) = queue.send("Hello").await {
eprintln!("Send failed: {}", e);
}
// Receive a message
match queue.receive().await {
Ok(Some(msg)) => println!("Received message: {}", msg),
Ok(None) => println!("Queue is empty"),
Err(e) => eprintln!("Receive failed: {}", e),
}
// Close the queue
drop(queue);
}
use tokio_mpmc::channel;
#[tokio::main]
async fn main() {
// Create a channel with capacity of 100
let (tx, rx) = channel(100);
// Send a message
if let Err(e) = tx.send("Hello").await {
eprintln!("Send failed: {}", e);
}
// Receive a message
match rx.recv().await {
Ok(Some(msg)) => println!("Received message: {}", msg),
Ok(None) => println!("Channel is closed"),
Err(e) => eprintln!("Receive failed: {}", e),
}
// Close the channel
drop(tx);
}
cargo criterion --message-format=json | criterion-table > BENCHMARKS.md
tokio-mpsc-channel |
tokio-mpmc-channel |
tokio-mpmc-queue |
flume |
|
|---|---|---|---|---|
non-io |
1.39 ms (✅ 1.00x) |
65.38 us (🚀 21.21x faster) |
168.86 us (🚀 8.21x faster) |
773.68 us (✅ 1.79x faster) |
io |
197.97 ms (✅ 1.00x) |
46.32 ms (🚀 4.27x faster) |
46.83 ms (🚀 4.23x faster) |
197.76 ms (✅ 1.00x faster) |
Note:
non-iomeans no IO operation,iomeans IO operation.
See benchmark code
This project is licensed under the Apache-2.0 License. See the LICENSE file for details.