Skip to content

Instantly share code, notes, and snippets.

@kumatch
Created April 15, 2012 12:10
Show Gist options
  • Save kumatch/2392366 to your computer and use it in GitHub Desktop.
Save kumatch/2392366 to your computer and use it in GitHub Desktop.
async.js forEach block
var doTask = function (value, callback) {
setTimeout(callback(value), 10);
};
var list_count = 100000;
var check_count = list_count / 10;
var list = [];
for (var i = 0; i < list_count; i++) list.push(i);
var http = require('http');
var async = require('async');
http.createServer(function (request, response) {
response.end('HTTP Response OK.');
}).listen(3000);
(function OtherTask() {
console.log('Other task.');
process.nextTick(OtherTask);
})();
(function EachTest() {
async.forEach(list, function (v, next) {
doTask(v, function (result) {
if ((result % check_count) == 0) {
console.log('doTask: ' + result);
}
});
next();
}, function (err) {
if (err) console.log(err);
});
console.log('Done.');
process.nextTick(EachTest);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment