node.js - running a task in parallel in nodejs -


this seems work:

function callloop (n) {   function caller () {     console.log("hello " + n);     settimeout(function () {       caller();     }, 10000);   }    caller(); }  (var = 0; < 5; i++) {   callloop(i); } 

settimeout, in example, instead long-running network call. "correct" way parallelize these network calls?

check out async.parallel:

var async = require( 'async' );  function callloop (n) {   function caller () {     console.log("hello " + n);     settimeout(function () {       caller();     }, 10000);   }    caller(); }  var functions = []; (var = 0; < 5; i++) {   functions.push(callloop.bind(null, i)); }  async.parallel(functions); 

Comments

Popular posts from this blog

ruby on rails - Is it the correct way to implement belongs_to relation with factory girl? -

geolocation - Windows Phone 8 - Keeping background location tracking active beyond four hours -

Uncaught TypeError: Cannot read property 'parentNode' of null javascript -