As far as I know, NodeJS doesn't run promises in parallel, it runs them concurrently as it is a single threaded event loop architecture. Ability to run things in parallel by creating a new child process to take advantage of multi-core CPUs. but when i run this test it shows the result of running in parallel. please help me explain
const a = new Promise(resolve => setTimeout(() => resolve("a"), 2000))
const b = new Promise(resolve => setTimeout(() => resolve("b"), 2000))
const c = new Promise(resolve => setTimeout(() => resolve("c"), 2000))
const begin = Date.now();
async function test() {
const promises = [a, b, c];
const [output1, output2, output3] = await Promise.all(promises);
return `parallel is done: ${output1} ${output2} ${output3}`;
}
test().then((arr)=>{
console.log(arr);
console.log( "time :", Date.now()- begin);
})
// parallel is done: a b c
//time : 2010