#async-channel #channel #request-response #response #request #async #sender

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

#2124 in Asynchronous

Download history 1/week @ 2024-11-08 8/week @ 2024-12-06 5/week @ 2024-12-13 23/week @ 2025-01-17 86/week @ 2025-01-24 13/week @ 2025-01-31 34/week @ 2025-02-07 24/week @ 2025-02-14

77 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–15MB
~211K SLoC