Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Some async pattern

View proof.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
var tags = ['tag1', 'tag2', 'tag3'];
 
(function oneIteration() {
var item = tags.shift();
if (item) {
doAsyncJob(item, oneIteration);
} else {
allDone();
}
})();
 
function allDone() {
console.log('all done');
}
 
function doAsyncJob(item, done) {
console.log('async', item);
setTimeout(done, 1000 * Math.random());
}
View proof.js
1 2 3 4 5
$ node proof.js
async tag1
async tag2
async tag3
all done

try it actually async...


...
function doAsyncJob(item, done) {
  //don't callback right away...
  process.nextTick(function(){
    console.log('async', item);
    setTimeout(done, 1000 * Math.random());
  });
}

Okay... nm.. didn't notice the recursive call in oneIteration...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.