pub struct JsonRpcClient { /* private fields */ }Expand description
Low-level JSON-RPC 2.0 client over Content-Length-framed streams.
§Cancel safety
All public methods (write, send_request) are cancel-safe: the
actual bytes hit the wire on a dedicated background actor task, so
dropping the caller’s future after await returns Pending cannot
produce a partial frame on the wire. Frames either land atomically or
the underlying I/O fails. See cancel-safety review artifact for the
full RFD-400 reasoning.
Implementations§
Source§impl JsonRpcClient
impl JsonRpcClient
Sourcepub fn new(
writer: impl AsyncWrite + Unpin + Send + 'static,
reader: impl AsyncRead + Unpin + Send + 'static,
notification_tx: Sender<JsonRpcNotification>,
request_tx: UnboundedSender<JsonRpcRequest>,
) -> Self
pub fn new( writer: impl AsyncWrite + Unpin + Send + 'static, reader: impl AsyncRead + Unpin + Send + 'static, notification_tx: Sender<JsonRpcNotification>, request_tx: UnboundedSender<JsonRpcRequest>, ) -> Self
Create a new client from async read/write streams.
Spawns two background tasks: a reader that dispatches incoming
messages to pending request channels, the notification broadcast,
or the request-forwarding channel; and a writer actor that owns the
underlying AsyncWrite and serializes frames atomically.
Sourcepub async fn send_request(
&self,
method: &str,
params: Option<Value>,
) -> Result<JsonRpcResponse, Error>
pub async fn send_request( &self, method: &str, params: Option<Value>, ) -> Result<JsonRpcResponse, Error>
Send a JSON-RPC request and wait for the matching response.
§Cancel safety
Cancel-safe. The frame is committed to the wire via the writer
actor before this future yields; cancelling the await drops the
response oneshot but does not desync the transport. The pending-
requests map is cleaned up automatically (the PendingGuard drop
removes the entry, and the read loop’s response handling tolerates
a missing entry).
Sourcepub async fn write<T: Serialize>(&self, message: &T) -> Result<(), Error>
pub async fn write<T: Serialize>(&self, message: &T) -> Result<(), Error>
Write a Content-Length-framed JSON-RPC message to the transport.
§Cancel safety
Cancel-safe. Pre-serializes the body, enqueues it on the writer actor’s command channel, and awaits an ack. Caller cancellation drops the ack receiver; the actor still completes the frame and flushes. A partial frame can never appear on the wire.