Skip to main content

Crate pending_requests

Crate pending_requests 

Source
Expand description

Track in-flight requests and await their responses by key.

A PendingRequests registry lets one task register a request under a key, hand back a ResponseWaiter future, and have another task deliver the matching response later. This is the classic pattern behind request/response protocols multiplexed over a single connection.

let requests = PendingRequests::<u64, String>::new();
let waiter = requests.prepare_response(1).unwrap();

// ... elsewhere, when the response for key `1` arrives:
requests.handle_response(1, "pong".to_string()).unwrap();

assert_eq!(waiter.await.unwrap(), "pong");

Structs§

PendingRequests
A registry of in-flight requests awaiting responses, keyed by K.
ResponseWaiter
A future that resolves with the response for a single request.

Enums§

Error