aboutsummaryrefslogtreecommitdiff
path: root/jsonrpc/src/client
diff options
context:
space:
mode:
authorhozan23 <hozan23@karyontech.net>2024-06-14 22:49:53 +0200
committerhozan23 <hozan23@karyontech.net>2024-06-14 22:49:53 +0200
commit3429caa87699d986f799a11f6e0f4526e723b655 (patch)
treee548c356fca4eb76742e29d4bab05007468ed14b /jsonrpc/src/client
parent0c0699c0460c1b149915729223eec701bde481df (diff)
jsonrpc: client use unbounded channels as buffer for sending requests & clean up examples
Diffstat (limited to 'jsonrpc/src/client')
-rw-r--r--jsonrpc/src/client/message_dispatcher.rs4
-rw-r--r--jsonrpc/src/client/mod.rs2
-rw-r--r--jsonrpc/src/client/subscriber.rs4
3 files changed, 3 insertions, 7 deletions
diff --git a/jsonrpc/src/client/message_dispatcher.rs b/jsonrpc/src/client/message_dispatcher.rs
index a803f6e..aa47cec 100644
--- a/jsonrpc/src/client/message_dispatcher.rs
+++ b/jsonrpc/src/client/message_dispatcher.rs
@@ -8,8 +8,6 @@ use crate::{message, Error, Result};
use super::RequestID;
-const CHANNEL_CAP: usize = 10;
-
/// Manages client requests
pub(super) struct MessageDispatcher {
chans: Mutex<HashMap<RequestID, Sender<message::Response>>>,
@@ -26,7 +24,7 @@ impl MessageDispatcher {
/// Registers a new request with a given ID and returns a Receiver channel
/// to wait for the response.
pub(super) async fn register(&self, id: RequestID) -> Receiver<message::Response> {
- let (tx, rx) = async_channel::bounded(CHANNEL_CAP);
+ let (tx, rx) = async_channel::unbounded();
self.chans.lock().await.insert(id, tx);
rx
}
diff --git a/jsonrpc/src/client/mod.rs b/jsonrpc/src/client/mod.rs
index 1225f13..9c07509 100644
--- a/jsonrpc/src/client/mod.rs
+++ b/jsonrpc/src/client/mod.rs
@@ -147,7 +147,7 @@ impl Client {
let msg = selfc.conn.recv().await?;
if let Err(err) = selfc.handle_msg(msg).await {
error!(
- "Failed to handle a new received msg from the connection {} : {err}",
+ "Handle a msg from the endpoint {} : {err}",
selfc.conn.peer_endpoint()?
);
}
diff --git a/jsonrpc/src/client/subscriber.rs b/jsonrpc/src/client/subscriber.rs
index d47cc2a..168f16e 100644
--- a/jsonrpc/src/client/subscriber.rs
+++ b/jsonrpc/src/client/subscriber.rs
@@ -11,8 +11,6 @@ use crate::{
Error, Result,
};
-const CHANNEL_CAP: usize = 10;
-
/// Manages subscriptions for the client.
pub(super) struct Subscriber {
subs: Mutex<HashMap<SubscriptionID, Sender<serde_json::Value>>>,
@@ -31,7 +29,7 @@ impl Subscriber {
}
pub(super) async fn subscribe(&self, id: SubscriptionID) -> Receiver<serde_json::Value> {
- let (ch_tx, ch_rx) = async_channel::bounded(CHANNEL_CAP);
+ let (ch_tx, ch_rx) = async_channel::unbounded();
self.subs.lock().await.insert(id, ch_tx);
ch_rx
}