2

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]
     });
   }
}`
1
  • yes, you can do it. Commented May 6, 2019 at 7:10

1 Answer 1

3

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);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.