Send a JSON-RPC request and wait for the response.
(
&self,
method: &str,
params: Option<Value>,
)
| 421 | |
| 422 | /// Send a JSON-RPC request and wait for the response. |
| 423 | async fn call<T: serde::de::DeserializeOwned>( |
| 424 | &self, |
| 425 | method: &str, |
| 426 | params: Option<Value>, |
| 427 | ) -> Result<T, PluginSubprocessError> { |
| 428 | let _rpc_guard = self.rpc_lock.lock().await; |
| 429 | let id = self.next_id(); |
| 430 | self.write_request(id, method, params).await?; |
| 431 | |
| 432 | // Read response with timeout |
| 433 | let response = tokio::time::timeout(self.timeout, self.read_response_for_id(id)) |
| 434 | .await |
| 435 | .map_err(|_| PluginSubprocessError::Timeout)??; |
| 436 | |
| 437 | if let Some(err) = response.error { |
| 438 | return Err(err.into()); |
| 439 | } |
| 440 | |
| 441 | let result = response.result.unwrap_or(Value::Null); |
| 442 | serde_json::from_value(result).map_err(Into::into) |
| 443 | } |
| 444 | |
| 445 | async fn write_request( |
| 446 | &self, |
no test coverage detected