Skip to content

Instantly share code, notes, and snippets.

Created April 21, 2010 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/373840 to your computer and use it in GitHub Desktop.
Save anonymous/373840 to your computer and use it in GitHub Desktop.
var sys = require('sys')
function processAll (items, callback) {
function next () {
var item = items.pop()
if(item == null)
return callback()
processOne(item, function () {
if(items.length % 1000 == 0)
sys.puts("Remaining: " + items.length)
next()
})
}
next()
}
function processOne (item, callback) {
// Simulate some work
setTimeout(callback, 2)
}
var items = []
for (i = 0; i < 400000; i++)
items.push(i)
processAll(items, function() {
sys.puts("done")
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment