Crate bidirectional_channel[][src]

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::Respond; // Don't forget to import this trait
let (requester, responder) = bidirectional_channel::bounded(10);
let future_response = requester.send(String::from("hello")).await.unwrap();

// This side of the channel receives Strings, and responds with their length
let received_request = responder.recv().await.unwrap();
let len = received_request.len(); // Deref coercion to the actual request
received_request.respond(len).unwrap();

assert!(future_response.await.unwrap() == 5);

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 Respond::respond, or destructured.

Requester

Represents the initiator for the request-response exchange

Responder

The receiving side of a channel.

UnRespondedRequest

Represents that the Requester associated with this communication is still waiting for a response. Must be used by calling Respond::respond.

Traits

Respond

Represents fullfilling a Requester’s request. This trait is sealed - types external to this crate may not implement it.

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

Type Definitions

FutureResponse

Represents waiting for the Responder to Respond::respond.