Skip to content

Commit

Permalink
jsonrpc/client: close the subscription channel when calling unsubscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
hozan23 committed Jun 22, 2024
1 parent 6c793e7 commit eed5fdb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 1 addition & 2 deletions jsonrpc/examples/pubsub_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ async fn run_client() {
.await
.expect("Build a client");

let clientc = client.clone();
smol::spawn(async move {}).detach();

let sub = client
Expand All @@ -34,7 +33,7 @@ async fn run_client() {

loop {
Timer::after(Duration::from_millis(500)).await;
let _: Pong = clientc
let _: Pong = client
.call("Calc.ping", ())
.await
.expect("Send ping request");
Expand Down
4 changes: 3 additions & 1 deletion jsonrpc/src/client/subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ impl Subscriptions {

/// Unsubscribe from the provided subscription id.
pub(super) async fn unsubscribe(&self, id: &SubscriptionID) {
self.subs.lock().await.remove(id);
if let Some(sub) = self.subs.lock().await.remove(id) {
sub.close();
}
}

/// Notifies the subscription about the given notification.
Expand Down
6 changes: 3 additions & 3 deletions jsonrpc/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ impl Server {
match selfc.listener.accept().await {
Ok(conn) => {
if let Err(err) = selfc.handle_conn(conn).await {
error!("Failed to handle a new conn: {err}")
error!("Handle a new connection: {err}")
}
}
Err(err) => {
error!("Failed to accept a new conn: {err}")
error!("Accept a new connection: {err}")
}
}
}
Expand Down Expand Up @@ -249,7 +249,7 @@ impl Server {
trace!("--> new request {msg}");
let on_complete = |result: TaskResult<Result<()>>| async move {
if let TaskResult::Completed(Err(err)) = result {
error!("Failed to handle a request: {err}");
error!("Handle a new request: {err}");
}
};
let selfc = self.clone();
Expand Down

0 comments on commit eed5fdb

Please sign in to comment.