bidirectional-channel

Crates.iobidirectional-channel
lib.rsbidirectional-channel
version0.3.1
sourcesrc
created_at2021-06-08 03:04:39.176656
updated_at2021-07-08 16:58:01.938127
descriptionA channel where receivers can respond to a message, and senders can wait for a response.
homepage
repositoryhttps://github.com/aatifsyed/bidirectional-channel
max_upload_size
id407581
size11,574
Aatif Syed (aatifsyed)

documentation

https://docs.rs/bidirectional-channel

README

bidirectional-channel

Async channel with request-response semantics

Crates.io version Download docs.rs docs
use bidirectional_channel::{bounded};
use futures::join;

let (requester, responder) = bounded(1);

// A requesting task
let requester = async {
    requester
        .send("hello")
        .await
        .expect("Responder or UnRespondedRequest was dropped")
};

// A responding task.
// This receives an &str, and returns its length
let responder = async {
    let request = responder.recv().await.expect("Requester was dropped");
    let len = request.len();
    request.respond(len).unwrap()
};

// Perform the exchange
let (response, request) = join!(requester, responder);
assert!(request.len() == response)
Commit count: 23

cargo fmt