var data = []; for (var i = 0; i < 100; i = i + 5) { data.push(i); } displayArray(data); $('#output').append('Lets start Parallel Processing' + dateOutput() + '<br/>'); async.map(data, processData, function (err,result) { if (err) { $('#output').append('OOPS! How is this possible?' + "<br/>"); } $('#output').append('Parallel Processing Done At ' + dateOutput() + '<br/>'); displayArray(result); $('#output').append('Lets Start Same Operation In Series ' + dateOutput() + '<br/>'); async.mapSeries(data, processData, function (err,result) { if (err) { $('#output').append('OOPS! How is this possible?' + "<br/>"); } $('#output').append('Series Processing Done At ' + dateOutput() + '<br/>'); displayArray(result); $('#output').append('Lets Start Same Operation In Series But With 5 at time ' + dateOutput() +'<br/>'); async.mapLimit(data, 5, processData, function (err,result) { if (err) { $('#output').append('OOPS! How is this possible?' + "<br/>"); } $('#output').append('Series Processing Done ' + dateOutput() + '<br/>'); displayArray(result); }); }); }); function processData(item, callback) { //we are just diving the number by 5 //but we can actually do a very long process here setTimeout(function () { var new_item = (item / 5); callback(null, new_item); //no error //incase of error pass the error in callback function }, 500); } function displayArray(to_display) { $('#output').append('Our Array<br/>'); $('#output').append('====================<br/>'); for (var i = 0; i < to_display.length; i++) { $('#output').append(to_display[i] + ","); } $('#output').append('<br/>' + '====================' + '<br/>'); } function dateOutput() { var date = new Date(); return date.getHours() + ":" + +date.getMinutes() + ":" + +date.getSeconds(); }