From 3429caa87699d986f799a11f6e0f4526e723b655 Mon Sep 17 00:00:00 2001 From: hozan23 Date: Fri, 14 Jun 2024 22:49:53 +0200 Subject: jsonrpc: client use unbounded channels as buffer for sending requests & clean up examples --- jsonrpc/src/client/message_dispatcher.rs | 4 +--- jsonrpc/src/client/mod.rs | 2 +- jsonrpc/src/client/subscriber.rs | 4 +--- 3 files changed, 3 insertions(+), 7 deletions(-) (limited to 'jsonrpc/src/client') 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>>, @@ -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 { - 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>>, @@ -31,7 +29,7 @@ impl Subscriber { } pub(super) async fn subscribe(&self, id: SubscriptionID) -> Receiver { - 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 } -- cgit v1.2.3