Last active
December 22, 2015 19:09
-
-
Save vicapow/6518095 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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