function heavyCalculationTask(param) {}
for(let i = 0; i<5000;i++) {
heavyCalculationTask(i)
}
I'm wondering if we can somewhat executing heavyCalculationTask
parallelly, to fully utilize the number of cores we have on the machine, instead of letting it looping one by one?
Initially I thought of turning heavyCalculationTask
into returning promise
and eventually use Promise.all
to wait for all the task to be completed, but guess it doesn't help, turning it into Promise just changing the order of execution, in terms of total duration spent still similar if not worse
Another idea is to move heavyCalculationTask
into it's own file and using worker_thread
to execute? But before jumping into that I'm wondering if there is any other alternatives