A question regarding "everything runs in parallel except your code" from someone new to Node.js. This is an obviously artificial example, but let's say I want to create a math library containing a function factorize()
which behaves as follows:
var http = require('http');
http.createServer(function (req, res) {
myMath.factorize(some_big_number,function(factors) {
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(JSON.stringify(factors));
}
}).listen(8000);
How can this be written so that it will "run in parallel"?
I've been looking at the parsing code from this library as an example that might take some processing time. Is the body of the code considered to be "your code", or does this "run in parallel"?
If not: What do I need to do when writing factorize()
so that it is also non-blocking/behaves like a client? Is using EventEmitter sufficient?
If so: Is my best option still to use child processes as suggested in this question?
Apologies in advance for any lack of clarity.