mirror of
https://github.com/openai/codex.git
synced 2026-10-20 17:38:45 +00:00
Reduce generic code duplication in RPC and Markdown rendering (#47751)
## Why RPC sending and waiting do not depend on request or response types, and Markdown layout does not depend on the parser iterator. Share these implementations across typed calls and parser variants. ## What changed - Extract `RpcClient::send_request_and_wait` into a non-generic async method, preserving registration before serialization and disconnected-client error precedence. - Remove the iterator type parameter from `Writer` and pass iterators to event traversal methods, retaining static dispatch and dropping the parser before rendering state, including on unwind. - Update streaming rendering and existing rendering tests to use the separate parser. GitOrigin-RevId: 4cc07223111b7c08211028948d13fe04598f8fc7
This commit is contained in:
@@ -653,6 +653,23 @@ impl RpcClient {
|
||||
return Err(RpcCallError::Json(err));
|
||||
}
|
||||
};
|
||||
let response = self
|
||||
.send_request_and_wait(method, request_id, params, response_rx, call_timeout)
|
||||
.await?;
|
||||
serde_json::from_value(response).map_err(RpcCallError::Json)
|
||||
}
|
||||
|
||||
// Sending and waiting are independent of P and T, so share this future
|
||||
// across typed calls. Register and serialize in call_inner in that order:
|
||||
// a disconnected client must still take precedence over a serialization error.
|
||||
async fn send_request_and_wait(
|
||||
&self,
|
||||
method: &str,
|
||||
request_id: RequestId,
|
||||
params: Value,
|
||||
response_rx: oneshot::Receiver<RpcCompletion>,
|
||||
call_timeout: RpcCallTimeout,
|
||||
) -> Result<Value, RpcCallError> {
|
||||
if self
|
||||
.write_tx
|
||||
.send(JSONRPCMessage::Request(JSONRPCRequest {
|
||||
@@ -695,8 +712,7 @@ impl RpcClient {
|
||||
};
|
||||
let completion = response.map_err(|_| RpcCallError::Closed)?;
|
||||
completion.record_receipt(method);
|
||||
let response = completion.result?;
|
||||
serde_json::from_value(response).map_err(RpcCallError::Json)
|
||||
completion.result
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user