Skip to main content

Crate spsc

Crate spsc 

Source
Expand description

§spsc: single producer, single consumer for no_std Rust

GitHub Workflow Status Crates.io docs.rs

An entangled sync sender + async receiver pair. A minimalistic, runtime-agnostic implementation.

Have a look at oneshot if you need a more-complete / more-complex / more-well tested implementation.

§Example

let (user_sender, user_receiver) = spsc::channel();

// You can use any runtime you like:
// tokio, smol, pollster, ... it works with everything!
let rx = tokio::spawn(async {
    // Receiving is async:
    // the call only returns once a value was sent,
    // or the sender was dropped.
    let user = user_receiver.await.unwrap();
    assert_eq!(user, "Max Mustermann");
});

// Sending is synchronous:
// The call does not need to happen inside a runtime.
user_sender.send("Max Mustermann").unwrap();

rx.await.unwrap();

§License

This project is tri-licensed under ISC OR MIT OR Apache-2.0. Contributions must be licensed under the same terms. Users may follow any one of these licenses, or all of them.

See the individual license texts at

Structs§

Receiver
Waits for the Sender to send a value.
RecvError
An error returned from receiver.await.
SendError
An error returned from Sender::send().
Sender
Call send() to send a value to Receiver.

Enums§

TryRecvError
An error returned from try_recv().

Functions§

channel
Returns an entangled (Sender, Receiver) pair.