aboutsummaryrefslogtreecommitdiff
path: root/jsonrpc
diff options
context:
space:
mode:
authorhozan23 <hozan23@proton.me>2024-03-13 02:07:31 +0100
committerhozan23 <hozan23@proton.me>2024-03-13 02:07:31 +0100
commitfc6fec0d8e69dac51e78b65dcc1a452c8a5b4901 (patch)
treed0330c6a9b08934aba2be48aa63f8883ca0db82f /jsonrpc
parent525a62c42fa3b3292a98ed5e8ec6703d9f2543f2 (diff)
jsonrpc: extend the example in the library
Diffstat (limited to 'jsonrpc')
-rw-r--r--jsonrpc/src/client.rs2
-rw-r--r--jsonrpc/src/codec.rs2
-rw-r--r--jsonrpc/src/lib.rs10
3 files changed, 11 insertions, 3 deletions
diff --git a/jsonrpc/src/client.rs b/jsonrpc/src/client.rs
index dc36c0d..efbaf50 100644
--- a/jsonrpc/src/client.rs
+++ b/jsonrpc/src/client.rs
@@ -54,7 +54,7 @@ impl Client {
let mut buffer = vec![];
if let Some(t) = self.config.timeout {
- self.codec.read_until_timeout(&mut buffer, t).await?;
+ self.codec.read_until_with_timeout(&mut buffer, t).await?;
} else {
self.codec.read_until(&mut buffer).await?;
};
diff --git a/jsonrpc/src/codec.rs b/jsonrpc/src/codec.rs
index 451cdb4..4a70412 100644
--- a/jsonrpc/src/codec.rs
+++ b/jsonrpc/src/codec.rs
@@ -94,7 +94,7 @@ impl Codec {
Ok(())
}
- pub async fn read_until_timeout(&self, buffer: &mut Vec<u8>, t: u64) -> Result<usize> {
+ pub async fn read_until_with_timeout(&self, buffer: &mut Vec<u8>, t: u64) -> Result<usize> {
timeout(std::time::Duration::from_secs(t), self.read_until(buffer)).await?
}
}
diff --git a/jsonrpc/src/lib.rs b/jsonrpc/src/lib.rs
index df66363..3e0eb8f 100644
--- a/jsonrpc/src/lib.rs
+++ b/jsonrpc/src/lib.rs
@@ -18,6 +18,14 @@
//! let msg: String = serde_json::from_value(params)?;
//! Ok(serde_json::json!(format!("Hello {msg}!")))
//! }
+//!
+//! async fn foo(&self, params: Value) -> Result<Value, JsonRPCError> {
+//! Ok(serde_json::json!("foo!"))
+//! }
+//!
+//! async fn bar(&self, params: Value) -> Result<Value, JsonRPCError> {
+//! Ok(serde_json::json!("bar!"))
+//! }
//! }
//!
//! // Server
@@ -30,7 +38,7 @@
//! let server = Server::new(listener, config, ex.clone());
//!
//! // Register the HelloWorld service
-//! register_service!(HelloWorld, say_hello);
+//! register_service!(HelloWorld, say_hello, foo, bar);
//! server.attach_service(HelloWorld{});
//!
//! // Starts the server