Is it possible to develop a javascript function in Node.js?

I am trying to execute a long run function from my main javascript file. I have 2 cpus, so how can I just unlock the function?

+6
source share
2 answers

The following is the node.js documentation for branching processes and child processes in node.

http://nodejs.org/api/child_process.html

It looks like you could do something like this.

var child = require('child_process').fork('child.js'); child.on("message", function(){}); 

And in this case, you will need a child.js file.

+7
source

For browser-side javascript, you use Web Workers for such a task, the functionality has been ported to NodeJS here. Web Worker Design for NodeJS , which wraps a child_process API call with a message passing to the web workers' capabilities.

+1
source

Source: https://habr.com/ru/post/920757/


All Articles