let's say we have a very CPU intensive code in NodeJs:
for (var i = 0; i < 1e10; i++){}
I've heard that under the hood nodejs uses pool threads for handling asynchronous code. So my question is: Is there any difference between converting this job to a promise such as:
const p = new Promise((resolve, reject) => {
for (var i = 0; i < 1e9; i++){
if (i == 1000) resolve("ok");
}
}).then(result => {
console.log('res ' + result)
})
and creating a new worker thread for handling this CPU intensive work, once nodejs already do that under the hood? Also if they are both the same under the hood why would people argue that using workers for handling cpu intensive is better if none of the ways blocks the event loop?
Question about nodeJs event loop, async vs multithreading in Nodejs.