pub struct Reusable<T> {
inner: Arc<Inner<T>>,
}
Expand description
A reusable One-Shot channel.
Essentially, a Reusable is a single producer, single consumer, channel, with a max depth of one. Many producers can be created over the lifecycle of a single consumer, however only zero or one producers can be live at any given time.
A Reusable<T>
can be used to hand out single-use Sender items, which can
be used to make a single reply.
A given Reusable<T>
can only ever have zero or one Sender<T>
s live at any
given time, and a response can be received through a call to Reusable::receive.
Fields§
§inner: Arc<Inner<T>>
Implementations§
source§impl<T> Reusable<T>
impl<T> Reusable<T>
sourcepub async fn sender(&self) -> Result<Sender<T>, ReusableError>
pub async fn sender(&self) -> Result<Sender<T>, ReusableError>
Create a sender for the given Reusable<T>
. If a sender is already
active, or the previous response has not yet been retrieved, an
error will be immediately returned.
This error can be cleared by awaiting Reusable::receive.
sourcepub async fn receive(&self) -> Result<T, ReusableError>
pub async fn receive(&self) -> Result<T, ReusableError>
Await the response from a created sender.
If a sender has not been created, this function will immediately return an error.
If the sender is dropped without sending a response, this function will return an error after the sender has been dropped.