Skip to content

Instantly share code, notes, and snippets.

@vicapow
Last active December 22, 2015 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vicapow/6518095 to your computer and use it in GitHub Desktop.
Save vicapow/6518095 to your computer and use it in GitHub Desktop.
// bad
// something async...
function doSomething(){
setTimeout(function(){
console.log('something 1')
// something async...
setTimeout(function(){
console.log('something 2')
// something async...
setTimeout(function(){
console.log("We're done!")
}, 1000)
}, 1000)
}, 1000)
}
// good
function doSomething(){
// something async...
setTimeout(something1, 1000)
}
function something1(){
// something async...
console.log('something 1')
setTimeout(something2, 1000)
}
function something2(){
// something async
console.log('something 2')
setTimeout(wereDone, 1000)
}
function wereDone(){
console.log("We're done!")
}
// even more good!
async.series([
function(done){
setTimeout(done, 1000)
}
, function(done){
console.log('something 1')
setTimeout(done, 1000)
}
, function(done){
console.log('something 2')
setTimeout(done, 1000)
}
, function(){
console.log("We're done!")
}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment