Skip to content

Commit 53342cc

Browse files
committed
rpc: Add new_with_timeout for RpcClient
1 parent 3a418e7 commit 53342cc

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/rpc/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ macro_rules! jsonrpc {
107107
Ok($struct_name { id: 0.into(), client })
108108
}
109109

110+
pub fn new_with_timeout(uri: &str, timeout: std::time::Duration) -> Result<Self, anyhow::Error> {
111+
let client = $crate::rpc::RpcClient::new_with_timeout(uri, timeout)?;
112+
Ok($struct_name { id: 0.into(), client })
113+
}
114+
110115
pub fn post<PARAM, RET>(&self, method:&str, params: PARAM)->Result<RET, $crate::rpc::RpcError>
111116
where
112117
PARAM:serde::ser::Serialize + Send + 'static,
@@ -195,6 +200,12 @@ macro_rules! jsonrpc_async {
195200
Ok($struct_name { id: 0.into(), client })
196201
}
197202

203+
#[cfg(not(target_arch="wasm32"))]
204+
pub fn new_with_timeout(uri: &str, timeout: std::time::Duration) -> Result<Self, anyhow::Error> {
205+
let client = $crate::rpc::RpcClient::new_with_timeout(uri, timeout)?;
206+
Ok($struct_name { id: 0.into(), client })
207+
}
208+
198209
#[cfg(not(target_arch="wasm32"))]
199210
pub fn post<PARAM, RET>(&self, method:&str, params: PARAM)->impl std::future::Future<Output =Result<RET, $crate::rpc::RpcError>> + Send + 'static
200211
where
@@ -288,6 +299,11 @@ impl RpcClient {
288299
Ok(Self { client, url })
289300
}
290301

302+
#[cfg(not(target_arch = "wasm32"))]
303+
pub fn new_with_timeout(uri: &str, timeout: std::time::Duration) -> Result<Self, anyhow::Error> {
304+
Self::with_builder(uri, |builder| builder.timeout(timeout))
305+
}
306+
291307
#[cfg(not(target_arch = "wasm32"))]
292308
pub fn new_with_cookie(uri: &str) -> Self {
293309
let url = reqwest::Url::parse(uri).expect("ckb uri, e.g. \"http://127.0.0.1:8114\"");

0 commit comments

Comments
 (0)