Skip to content

Commit 9fda724

Browse files
committed
electrum: use CoinRequest::Stop instead AtomicBool
1 parent bb9d549 commit 9fda724

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

rust/joinstr/src/electrum.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ use simple_nostr_client::nostr::bitcoin::consensus::encode::serialize_hex;
1616
use std::{
1717
collections::{BTreeMap, HashMap},
1818
fmt::{Debug, Display},
19-
sync::{
20-
atomic::{AtomicBool, Ordering},
21-
mpsc, Arc,
22-
},
19+
sync::mpsc,
2320
thread::{self, sleep},
2421
time::Duration,
2522
};
@@ -219,26 +216,20 @@ impl Client {
219216
id
220217
}
221218

222-
pub fn listen<RQ, RS>(self) -> (mpsc::Sender<RQ>, mpsc::Receiver<RS>, Arc<AtomicBool>)
219+
pub fn listen<RQ, RS>(self) -> (mpsc::Sender<RQ>, mpsc::Receiver<RS>)
223220
where
224221
RQ: Into<CoinRequest> + Debug + Send + 'static,
225222
RS: From<CoinResponse> + Debug + Send + 'static,
226223
{
227-
let stop = Arc::new(AtomicBool::new(false));
228224
let (sender, request) = mpsc::channel();
229225
let (response, receiver) = mpsc::channel();
230-
let cloned_stop = stop.clone();
231-
thread::spawn(move || self.listen_txs(response, request, stop));
226+
thread::spawn(move || self.listen_txs(response, request));
232227

233-
(sender, receiver, cloned_stop)
228+
(sender, receiver)
234229
}
235230

236-
fn listen_txs<RQ, RS>(
237-
mut self,
238-
send: mpsc::Sender<RS>,
239-
recv: mpsc::Receiver<RQ>,
240-
stop: Arc<AtomicBool>,
241-
) where
231+
fn listen_txs<RQ, RS>(mut self, send: mpsc::Sender<RS>, recv: mpsc::Receiver<RQ>)
232+
where
242233
RQ: Into<CoinRequest> + Debug + Send + 'static,
243234
RS: From<CoinResponse> + Debug + Send + 'static,
244235
{
@@ -256,11 +247,6 @@ impl Client {
256247
}
257248

258249
loop {
259-
// consumer ask to stop
260-
if stop.load(Ordering::Relaxed) {
261-
return;
262-
}
263-
264250
let mut received = false;
265251
// Handle requests from consumer
266252
// NOTE: some server implementation (electrs for instance) will answer by an empty

0 commit comments

Comments
 (0)