Created
April 15, 2012 12:10
-
-
Save kumatch/2392366 to your computer and use it in GitHub Desktop.
async.js forEach block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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