pub struct OutgoingRequests<O> { /* private fields */ }Expand description
Tracks requests sent to clients (outgoing from the server).
When the server sends a request to the client, it registers the request ID and receives a oneshot receiver. When the client’s response arrives, the server completes the request, sending the response to the waiting receiver.
The generic parameter O represents the response type that will be delivered
when the request completes.
§Example
use lsp_server_tokio::{OutgoingRequests, RequestId};
let mut outgoing: OutgoingRequests<String> = OutgoingRequests::new();
// Register an outgoing request
let rx = outgoing.register(1.into());
assert!(outgoing.is_pending(&1.into()));
// Simulate receiving a response
let completed = outgoing.complete(&1.into(), "result".to_string());
assert!(completed);
// Receiver gets the response
let result = rx.await.unwrap();
assert_eq!(result, "result");Implementations§
Source§impl<O> OutgoingRequests<O>
impl<O> OutgoingRequests<O>
Sourcepub fn complete(&mut self, id: &RequestId, response: O) -> bool
pub fn complete(&mut self, id: &RequestId, response: O) -> bool
Completes an outgoing request by sending the response to the waiting receiver.
Returns true if the request was pending and the response was sent,
false if the request was not found.
Note: This returns true even if the receiver was dropped (the response is
still considered “completed” from the queue’s perspective).
Sourcepub fn cancel(&mut self, id: &RequestId) -> bool
pub fn cancel(&mut self, id: &RequestId) -> bool
Cancels an outgoing request without sending a response.
The sender is dropped, causing the receiver to return RecvError.
Returns true if the request was pending, false otherwise.
Sourcepub fn is_pending(&self, id: &RequestId) -> bool
pub fn is_pending(&self, id: &RequestId) -> bool
Returns true if the request is currently pending.
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Returns the number of currently pending requests.