Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 我们可以使用多线程并行运行async()吗?_Node.js_Multithreading - Fatal编程技术网

Node.js 我们可以使用多线程并行运行async()吗?

Node.js 我们可以使用多线程并行运行async()吗?,node.js,multithreading,Node.js,Multithreading,在循环中,我正在执行一些db操作。我可以使用多线程的概念来调用异步函数“addInputs”以便它执行得更快吗 `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] }); }

在循环中,我正在执行一些db操作。我可以使用多线程的概念来调用异步函数“addInputs”以便它执行得更快吗

`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]
     });
   }
}`

虽然JavaScript没有多线程,但在这种情况下,您可以使用一种技巧,用承诺填充数组,然后立即等待它们:

const array = []
for(const id of ids) {
    array.push(addInputs (id));
}
const result =  await Promise.all(array);

是的,你能做到。