Skip to content

Kijewski/spsc

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

About

An entangled sync sender + async receiver pair.

Resources

License

Apache-2.0 and 2 other licenses found

Licenses found

Apache-2.0
LICENSE.Apache
ISC
LICENSE.ISC
MIT
LICENSE.MIT

Security policy

Stars

Watchers

Forks

Contributors

Languages