#response #request-response #async-channel

bidirectional-channel

A channel where receivers can respond to a message, and senders can wait for a response

7 releases

0.3.1 Jul 8, 2021
0.3.0 Jul 8, 2021
0.2.3 Jun 10, 2021
0.1.0 Jun 8, 2021

#47 in #async-channel

Download history 1/week @ 2024-10-09 1/week @ 2024-10-30 1/week @ 2024-11-06 2/week @ 2024-12-04 11/week @ 2024-12-11 101/week @ 2025-01-22

101 downloads per month

MIT/Apache

9KB
78 lines

bidirectional-channel

Async channel with request-response semantics

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)

Dependencies

~5–14MB
~198K SLoC