Reputation: 180
here in loop I'm doing some db operations. Can I use multi-threading concept to call async function "addInputs" so that it would execute faster?
`for(const temp of tx.vin) {
if (temp.txid) {
let results = await addInputs(temp.txid,temp.vout)
inputs.push({
"value": results[0],
"address": results[1]
});
}
}`
Upvotes: 2
Views: 119
Reputation: 18834
While JavaScript does not have multithreading, a trick you can use in this situation is to fill an array with promises, and then await them all at once:
const array = []
for(const id of ids) {
array.push(addInputs (id));
}
const result = await Promise.all(array);
Upvotes: 3