pub struct PendingRequests<K: Eq + Hash, R> { /* private fields */ }Expand description
A registry of in-flight requests awaiting responses, keyed by K.
Cloning is cheap and shares all state: register a request on one clone and
deliver its response from another. This is the expected way to use the
registry across tasks (e.g. a reader task calling handle_response while
many sender tasks await their ResponseWaiters).
Implementations§
Source§impl<K: Eq + Hash + Clone, R> PendingRequests<K, R>
impl<K: Eq + Hash + Clone, R> PendingRequests<K, R>
Sourcepub fn set_timeout(&self, timeout: Duration)
pub fn set_timeout(&self, timeout: Duration)
Set the default timeout applied to requests registered after this
call. Takes &self, so it works through a shared/cloned handle.
Already-registered requests keep the timeout they were created with.
Sourcepub fn prepare_response(&self, key: K) -> Result<ResponseWaiter<K, R>, Error>
pub fn prepare_response(&self, key: K) -> Result<ResponseWaiter<K, R>, Error>
Register a request under key, using the registry’s default timeout.
Returns Error::KeyAlreadyExists if a request with key is already
pending.
Sourcepub fn prepare_response_with_timeout(
&self,
key: K,
timeout: Duration,
) -> Result<ResponseWaiter<K, R>, Error>
pub fn prepare_response_with_timeout( &self, key: K, timeout: Duration, ) -> Result<ResponseWaiter<K, R>, Error>
Register a request under key with an explicit timeout.
Sourcepub fn handle_response(&self, key: K, response: R) -> Result<(), Error>
pub fn handle_response(&self, key: K, response: R) -> Result<(), Error>
Deliver response to the request registered under key.
Returns Error::KeyNotFound if no request is pending for key, or
Error::ReceiverDropped if the waiter was already dropped.
Sourcepub fn cancel(&self, key: &K) -> Result<(), Error>
pub fn cancel(&self, key: &K) -> Result<(), Error>
Cancel the request registered under key, causing its waiter to
resolve with Error::Canceled.
Returns Error::KeyNotFound if no request is pending for key.
Sourcepub fn cancel_all(&self) -> usize
pub fn cancel_all(&self) -> usize
Cancel every pending request, resolving all their waiters with
Error::Canceled. Returns the number of requests canceled.
Useful when a connection drops and all in-flight requests should fail at once.