Skip to main content

OutgoingRequests

Struct OutgoingRequests 

Source
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>

Source

pub fn new() -> Self

Creates a new empty outgoing request tracker.

Source

pub fn register(&mut self, id: RequestId) -> Receiver<O>

Registers an outgoing request and returns a receiver for the response.

The returned receiver will receive the response value when complete is called with a matching ID. If the request is cancelled via cancel, the receiver will return a RecvError.

Source

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).

Source

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.

Source

pub fn is_pending(&self, id: &RequestId) -> bool

Returns true if the request is currently pending.

Source

pub fn pending_count(&self) -> usize

Returns the number of currently pending requests.

Trait Implementations§

Source§

impl<O: Debug> Debug for OutgoingRequests<O>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<O> Default for OutgoingRequests<O>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<O> Freeze for OutgoingRequests<O>

§

impl<O> !RefUnwindSafe for OutgoingRequests<O>

§

impl<O> Send for OutgoingRequests<O>
where O: Send,

§

impl<O> Sync for OutgoingRequests<O>
where O: Send,

§

impl<O> Unpin for OutgoingRequests<O>

§

impl<O> UnsafeUnpin for OutgoingRequests<O>

§

impl<O> !UnwindSafe for OutgoingRequests<O>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.