Crate bidirectional_channel

Crate bidirectional_channel 

Source
Expand description

An async channel with request-response semantics.
When a Responder is asked to receive a request, it returns a ReceivedRequest, which should be used to communicate back to the sender

use bidirectional_channel::{bounded};
let (requester, responder) = bounded(1);
let requester = async { requester.send("hello").await.unwrap() };
let responder = async {
    let request = responder.recv().await.unwrap();
    let len = request.len();
    request.respond(len).unwrap()
};
let (response, request) = join!(requester, responder);
assert!(request.len() == response)

Structs§

ReceivedRequest
Represents the request. This implements AsRef and AsMut for the request itself for explicit use. Alternatively, you may use Deref and DerefMut either explicitly, or coerced. Must be used by calling ReceivedRequest::respond, or destructured.
Requester
Represents the initiator for the request-response exchange
Responder
An async_std::channel::Receiver which receives an UnRespondedRequest<Req, Resp> instead of a Req. The receiving side of a channel.
UnRespondedRequest
Represents that the Requester associated with this communication is still waiting for a response.

Enums§

SendRequestError
Error returned when sending a request

Functions§

bounded
Create a bounded Requester-Responder pair.
That is, once the channel is full, future senders will yield when awaiting until there’s space again