If I'm not mistaken, you're looking for something along the lines of multithreading and/or computing multiple things at the same time.
Multiple executions at once
SIMD is beginning to find its way into Browsers, with Node implementations not far behind. Take a look at node-simd or MDN SIMD (browsers).
SIMD is still experimental, and only works on supported CPUs at the moment (obviously, since not all CPUs have this functionality). It executes multiple things at once, an example comparing normal JS to SIMD JS would be:
// Normal addition, 4 actions are executed.
var a = [1, 2, 3, 4];
var b = [5, 6, 7, 8];
var c = [];
c[0] = a[0] + b[0];
c[1] = a[1] + b[1];
c[2] = a[2] + b[2];
c[3] = a[3] + b[3];
c; // Array[6, 8, 10, 12]
// SIMD execution - all additions are processed simultaenously through the CPU
var a = SIMD.Float32x4(1, 2, 3, 4);
var b = SIMD.Float32x4(5, 6, 7, 8);
var c = SIMD.Float32x4.add(a,b);
c; // Float32x4[6, 8, 10, 12]
Multithreading
In regards to multithreading, webworkers
have existed in the Browser environment for a while now. This has been ported to Node fully according to the HTML spec as seen in this repository.
Here's a good explanation as to why webworkers
were even ported to Node in the first place, since you can already run child processes in other threads and on other CPUs with the child_process
module. node-webworker
is a great module since each process is run within its on context, and in its own node
process, so it is truly multithreading with node.
So, to run different processes on different CPUs, you would either adopt node-webworker
or use child_process
to spawn other threads to do separate actions at the same time with different CPU cores. node-webworker
can listen for events using the familiar postMessage
API, and child_process
will communicate through stdin / stdout / stderr
.
Hope that answers your question :)