#async-channel #request-response #channel #response #request #bounded-channel #async

bidirectional-channel

接收者可以响应消息的通道,发送者可以等待响应

7 个版本

0.3.1 2021 年 7 月 8 日
0.3.0 2021 年 7 月 8 日
0.2.3 2021 年 6 月 10 日
0.1.0 2021 年 6 月 8 日

#1777异步

每月 33 次下载

MIT/Apache

9KB
78

bidirectional-channel

具有请求-响应语义的异步通道

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)

依赖项

~5–18MB
~216K SLoC