How to properly write the following set of loops in Node.Js without blocking the event loop or without causing out of memory error.
What I have tried so far includes
- Combinations of setImmediate()/setInterval()
- The Async module see my code here
- Thread_a_gogo (this module is no more maintained)
The code.
for(var i = 0; i < 2000; i++)
for(var j = 0; i < 2000; j++)
for(var k = 0; k < 2000; k++)
console.log(i + ":" + j + ":" + k);
Also created a JSFiddle to play around here
async.jscode should work, you just have to actually use the asynchronoussetImmediate(cb)(etc) instead of immediately callingcb().