Skip to content

Commit

Permalink
If streams cannot be locked, it will cause a panic
Browse files Browse the repository at this point in the history
Signed-off-by: jokemanfire <[email protected]>
  • Loading branch information
jokemanfire committed Aug 8, 2024
1 parent 152ac12 commit 01c2d73
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/asynchronous/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ impl Client {

let (tx, mut rx): (ResultSender, ResultReceiver) = mpsc::channel(100);

// TODO: check return.
self.streams.lock().unwrap().insert(stream_id, tx);
if let Ok(mut streams) = self.streams.lock() {
streams.insert(stream_id, tx);
} else {
return Err(Error::Others("Failed to acquire lock on streams".to_string()));
}


self.req_tx
.send(msg)
Expand Down Expand Up @@ -136,8 +140,12 @@ impl Client {
}

let (tx, rx): (ResultSender, ResultReceiver) = mpsc::channel(100);
// TODO: check return
self.streams.lock().unwrap().insert(stream_id, tx);
if let Ok(mut streams) = self.streams.lock() {
streams.insert(stream_id, tx);
} else {
return Err(Error::Others("Failed to acquire lock on streams".to_string()));
}

self.req_tx
.send(msg)
.await
Expand Down

0 comments on commit 01c2d73

Please sign in to comment.