#channel #thread #messaging

message-channel

A simple thread-safe message channel implementation

1 unstable release

0.0.1 Nov 13, 2024

#17 in #threads

Download history 62/week @ 2024-11-15 68/week @ 2024-11-22 196/week @ 2024-11-29 135/week @ 2024-12-06 101/week @ 2024-12-13 39/week @ 2024-12-20 75/week @ 2024-12-27 19/week @ 2025-01-03 231/week @ 2025-01-10 78/week @ 2025-01-17 29/week @ 2025-01-24 14/week @ 2025-01-31 21/week @ 2025-02-07 28/week @ 2025-02-14 63/week @ 2025-02-21 112/week @ 2025-02-28

228 downloads per month
Used in 33 crates (9 directly)

MIT license

7KB
71 lines

📬 message-channel

This Rust library provides a simple, thread-safe channel implementation for message passing between a single Sender and a single Receiver. The channel is non-blocking on the receiving end, making it ideal for cases where you want to check for messages without waiting.

✨ Features

  • Single-Producer, Single-Consumer (SPSC): Only one Sender and one Receiver can interact with a channel.
  • Non-blocking Receiver: The try_recv method returns immediately, either with a message (Some) or indicating that the queue is empty (None).
  • Thread-Safe: Uses Mutex and Arc to safely share data between threads.

📦 Installation

To use message-channel, add it to your Cargo.toml:

[dependencies]
message-channel = "0.0.1"

🚀 Usage

Here's a simple example of how to use message-channel:

use message_channel::Channel;

fn main() {
    let (sender, receiver) = Channel::create();

    // Send a message
    sender.send(42).unwrap();

    // Receive a message
    let message = receiver.recv().unwrap();
    assert_eq!(message, 42);
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

No runtime deps