Skip to content

Instantly share code, notes, and snippets.

@chrisinajar
Created April 27, 2012 17:36
Show Gist options
  • Save chrisinajar/2511098 to your computer and use it in GitHub Desktop.
Save chrisinajar/2511098 to your computer and use it in GitHub Desktop.
var doStuff = function(val, cb) {
// Call the callback later!
setTimeout(function() { cb(val); }, 1);
}
var total = 5;
for (var i = 0, c = 0; i < total; ++i) {
doStuff(i, function(val) {
console.log('Got a return value! ' + val);
if (++c === total) {
console.log('All 5 are done');
}
});
}
console.log('This debug statement will appear first! Weird, huh...');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment