Skip to content

Commit f52712b

Browse files
committed
joinstr: return gracefully is caller dropped the channel in electrum::Client::listen_txs()
1 parent fa5156f commit f52712b

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

rust/joinstr/src/electrum.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,11 @@ impl Client {
341341
self.inner.try_send_batch(batch.iter().collect())
342342
{
343343
retry += 1;
344-
if retry > 10 {
345-
send.send(CoinResponse::Error(format!("electrum::Client::listen_txs() Fail to send bacth request: {:?}", e)).into()).expect("caller dropped");
346-
}
344+
if retry > 10 && send.send(CoinResponse::Error(format!("electrum::Client::listen_txs() Fail to send bacth request: {:?}", e)).into()).is_err() {
345+
// NOTE: caller has dropped the channel
346+
// == Close request
347+
return;
348+
}
347349
thread::sleep(Duration::from_millis(50));
348350
}
349351
}
@@ -429,9 +431,14 @@ impl Client {
429431
txs.push(tx);
430432
}
431433
Response::Error(e) => {
432-
// TODO: do not unwrap
433-
send.send(CoinResponse::Error(e.to_string()).into())
434-
.unwrap();
434+
if send
435+
.send(CoinResponse::Error(e.to_string()).into())
436+
.is_err()
437+
{
438+
// NOTE: caller has dropped the channel
439+
// == Close request
440+
return;
441+
}
435442
}
436443
_ => {}
437444
}
@@ -455,10 +462,14 @@ impl Client {
455462
}
456463
Ok(None) => {}
457464
Err(e) => {
458-
log::error!("Client::listen_txs() error receiving response: {e}");
459-
// TODO: do not unwrap
460-
send.send(CoinResponse::Error(e.to_string()).into())
461-
.unwrap();
465+
if send
466+
.send(CoinResponse::Error(e.to_string()).into())
467+
.is_err()
468+
{
469+
// NOTE: caller has dropped the channel
470+
// == Close request
471+
return;
472+
}
462473
}
463474
}
464475
if received {

0 commit comments

Comments
 (0)