Create vector of thread handles to spawn threads

Signed-off-by: nickfarrow <nick@nickfarrow.com>
This commit is contained in:
nickfarrow 2022-04-05 12:11:52 +10:00
parent 9c0141b5e3
commit adef166b22
No known key found for this signature in database
GPG Key ID: 992AF78384653A47

View File

@ -127,10 +127,11 @@ impl WalletSync for EsploraBlockchain {
.take(self.concurrency as usize)
.cloned();
let handles = scripts.map(move |script| {
let mut handles = vec![];
for script in scripts {
let client = self.url_client.clone();
// make each request in its own thread.
std::thread::spawn(move || {
handles.push(std::thread::spawn(move || {
let mut related_txs: Vec<Tx> = client._scripthash_txs(&script, None)?;
let n_confirmed =
@ -152,10 +153,11 @@ impl WalletSync for EsploraBlockchain {
}
}
Result::<_, Error>::Ok(related_txs)
})
});
}));
}
let txs_per_script: Vec<Vec<Tx>> = handles
.into_iter()
.map(|handle| handle.join().unwrap())
.collect::<Result<_, _>>()?;
let mut satisfaction = vec![];