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.
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();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