]> Untitled Git - bdk/commitdiff
Create vector of thread handles to spawn threads
authornickfarrow <nick@nickfarrow.com>
Tue, 5 Apr 2022 02:11:52 +0000 (12:11 +1000)
committernickfarrow <nick@nickfarrow.com>
Wed, 6 Apr 2022 06:10:59 +0000 (16:10 +1000)
Signed-off-by: nickfarrow <nick@nickfarrow.com>
src/blockchain/esplora/ureq.rs

index 9bfa378fc445afe6c009e28040b5ea99a9b8ceb5..55f1cf7643bd4884f89cdb380d9c49558234653a 100644 (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![];