From ad5f1d4a3909056a5a8c219028a3e97ace35507b Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Thu, 8 Jan 2026 13:31:37 +0800 Subject: [PATCH] rpc: Add new_with_timeout for RpcClient Signed-off-by: Eval EXEC --- src/rpc/mod.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/rpc/mod.rs b/src/rpc/mod.rs index baac5fa..2ba7403 100644 --- a/src/rpc/mod.rs +++ b/src/rpc/mod.rs @@ -107,6 +107,11 @@ macro_rules! jsonrpc { Ok($struct_name { id: 0.into(), client }) } + pub fn new_with_timeout(uri: &str, timeout: std::time::Duration) -> Result { + let client = $crate::rpc::RpcClient::new_with_timeout(uri, timeout)?; + Ok($struct_name { id: 0.into(), client }) + } + pub fn post(&self, method:&str, params: PARAM)->Result where PARAM:serde::ser::Serialize + Send + 'static, @@ -195,6 +200,12 @@ macro_rules! jsonrpc_async { Ok($struct_name { id: 0.into(), client }) } + #[cfg(not(target_arch="wasm32"))] + pub fn new_with_timeout(uri: &str, timeout: std::time::Duration) -> Result { + let client = $crate::rpc::RpcClient::new_with_timeout(uri, timeout)?; + Ok($struct_name { id: 0.into(), client }) + } + #[cfg(not(target_arch="wasm32"))] pub fn post(&self, method:&str, params: PARAM)->impl std::future::Future> + Send + 'static where @@ -288,6 +299,14 @@ impl RpcClient { Ok(Self { client, url }) } + #[cfg(not(target_arch = "wasm32"))] + pub fn new_with_timeout( + uri: &str, + timeout: std::time::Duration, + ) -> Result { + Self::with_builder(uri, |builder| builder.timeout(timeout)) + } + #[cfg(not(target_arch = "wasm32"))] pub fn new_with_cookie(uri: &str) -> Self { let url = reqwest::Url::parse(uri).expect("ckb uri, e.g. \"http://127.0.0.1:8114\"");