I try to execute a long run function from my main javascript file. I have 2 cpus so how can I just fork a function ?
Yes, there are but using the fork() method handles expensive requests. This is one method that can scale your application server. Other ways include the spawn() , exec() , and execFile() .
As a result, writing JavaScript is incredibly easy, and any working environment is similar to a complete browser. Node. js, on the other hand, only enables the V8 engine. Written JavaScript code, on the other hand, can run in any context, regardless of whether the V8 engine is supported.
Node. js is an open-source, cross-platform JavaScript runtime environment and library for running web applications outside the client's browser. Ryan Dahl developed it in 2009, and its latest iteration, version 15.14, was released in April 2021. Developers use Node.
A Fork Node has one incoming flow and multiple outgoing flows. Create a Fork Node through a Modeler explorer pane or an Activity Diagram: In a Modeler pane, right-click an Activity or Structured Activity Node, point to New, point to Control Node, and then click Fork Node.
Here is node.js documentation on forking and child processes in node.
http://nodejs.org/api/child_process.html
Looks like you might be able to do something like this.
var child = require('child_process').fork('child.js');
child.on("message", function(){});
And you would need the child.js file in this case.
For browser-side javascript you would use Web Workers for such a task, the functionality has been ported to NodeJS here Design of Web Workers for NodeJS which wraps child_process API call with the message passing abilities of Web Workers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With