M
M
Maxim Ivanov2017-06-07 14:12:14
Node.js
Maxim Ivanov, 2017-06-07 14:12:14

How to execute 1000 times one synchronous function in parallel in NodeJS?

I have one function, it is quite heavy (there may be a loop within a loop, etc.), the execution speed can vary from 10 s - 1 minute, as a result, I need to collect the output of this function together
// fn.js

module.exports = () => {
 // high operation
 console.log("time result", t);
}

// main.js
const fn = require("./fn.js");

// нужно выполнить эту функцию 1000 раз параллельно

How to achieve parallelism in NodeJS?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
rustler2000, 2017-06-07
@splincodewd

No way - the node works in one thread. Cut the function into pieces, and run in parts (itself, some wq or promises)

N
Negwereth, 2017-06-07
@Negwereth

https://github.com/pgriess/node-webworker

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question