3 unstable releases
0.2.1 | Jul 19, 2020 |
---|---|
0.2.0 | Jul 19, 2020 |
0.1.0 | Jul 4, 2020 |
#2053 in Asynchronous
15KB
246 lines
Scambio
Safe and efficient value exchanges between endpoint pairs.
Documentation is available at
License
This project is licensed under the Blue Oak Model License Version 1.0.0. If you are interested in contributing to this project, please read the file CONTRIBUTING.md first.
lib.rs
:
This crate allows asynchronous value exchanges between two endpoints.
Conceptually this is similar to having two channels, each with capacity 1.
Example
Create an exchange between a client A and a server B where A sends
u32
values to B and B acknowledges each value with a bool
, true
if the value is odd and false
otherwise.
let (mut a, mut b) = scambio::exchange();
let client = async move {
for i in 0 .. 10u32 {
assert!(a.send(i).await.is_ok());
assert_eq!(Some(i % 2 == 1), a.receive().await)
}
};
let server = async move {
while let Some(i) = b.receive().await {
assert!(b.send(i % 2 == 1).await.is_ok())
}
};
assert_eq!(futures::join!(client, server), ((), ()));
Dependencies
~470–780KB
~13K SLoC