| Crates.io | theta-sync |
| lib.rs | theta-sync |
| version | 0.1.0-alpha.1 |
| created_at | 2025-08-03 04:38:06.240165+00 |
| updated_at | 2025-08-04 13:24:02.282079+00 |
| description | A high-performance no_std MPSC channel with full Tokio compatibility |
| homepage | |
| repository | https://github.com/cwahn/theta-sync |
| max_upload_size | |
| id | 1779354 |
| size | 140,828 |
A high-performance, no_std compatible MPSC channel with full Tokio API compatibility.
theta-sync provides a multi-producer, single-consumer (MPSC) channel that serves as a drop-in replacement for tokio::sync::mpsc::unbounded_channel. It offers improved performance through lock-free atomic operations while maintaining complete API compatibility with Tokio.
tokio::sync::mpsc::unbounded_channelalloc)[dependencies]
theta-sync = "0.1"
For no_std environments:
[dependencies]
theta-sync = { version = "0.1", default-features = false }
use theta_sync::unbounded_channel;
#[tokio::main]
async fn main() {
let (tx, mut rx) = unbounded_channel();
// Send messages
tx.send("Hello").unwrap();
tx.send("World").unwrap();
// Receive messages
while let Some(msg) = rx.recv().await {
println!("Received: {}", msg);
}
}
use theta_sync::unbounded_channel;
fn main() {
let (tx, mut rx) = unbounded_channel();
tx.send(42).unwrap();
tx.send(84).unwrap();
assert_eq!(rx.try_recv().unwrap(), 42);
assert_eq!(rx.try_recv().unwrap(), 84);
}
theta-sync is a drop-in replacement for Tokio's unbounded MPSC channel:
// Simply change the import
// use tokio::sync::mpsc::unbounded_channel; // Before
use theta_sync::unbounded_channel; // After
let (tx, mut rx) = unbounded_channel();
// All Tokio APIs work identically
let weak_tx = tx.downgrade(); // Weak references
let count = tx.strong_count(); // Reference counting
let is_closed = tx.is_closed(); // State checking
let len = rx.len(); // Queue length
rx.close(); // Manual close
tx.closed().await; // Close notification
theta-sync uses a lock-free block-based design:
let (tx, _rx) = unbounded_channel();
let weak_tx = tx.downgrade();
drop(tx); // Channel stays open
if let Some(strong_tx) = weak_tx.upgrade() {
strong_tx.send("message").unwrap();
}
use theta_sync::{unbounded_channel, SendError, TryRecvError};
let (tx, mut rx) = unbounded_channel();
match tx.send(42) {
Ok(()) => println!("Sent successfully"),
Err(SendError(value)) => println!("Channel closed: {}", value),
}
match rx.try_recv() {
Ok(value) => println!("Received: {}", value),
Err(TryRecvError::Empty) => println!("Channel is empty"),
Err(TryRecvError::Disconnected) => println!("Channel is closed"),
}
Benchmarks show theta-sync delivers superior performance compared to Tokio's MPSC channel, with up to 2x better throughput in typical usage scenarios.
Run the comprehensive test suite:
cargo test # Run all tests
cargo bench # Run benchmarks
no_std compatibility for resource-constrained environmentsContributions are welcome! Please ensure:
cargo testcargo fmtcargo clippyLicensed under either of Apache-2.0 or MIT at your option.
Inspired by Tokio's MPSC channel design and optimized for modern Rust async ecosystems.
#![no_std]
extern crate alloc;
use theta_sync::unbounded_channel;
use alloc::vec::Vec;
// Perfect for embedded async runtimes
fn sensor_data_processor() {
let (tx, mut rx) = unbounded_channel();
// Send sensor readings
tx.send(SensorReading { temp: 25.5, humidity: 60.0 }).unwrap();
// Process asynchronously
while let Ok(reading) = rx.try_recv() {
process_sensor_data(reading);
}
}
theta-sync automatically configures optimal block sizes:
theta-sync provides complete memory safety:
Run benchmarks yourself:
cargo bench
Benchmark categories:
Contributions welcome! Please read our contributing guidelines and ensure:
cargo testcargo benchcargo fmtcargo clippyLicensed under either of:
at your option.