Skip to content

Instantly share code, notes, and snippets.

@csanz
Created February 8, 2012 02:27
Show Gist options
  • Save csanz/1764649 to your computer and use it in GitHub Desktop.
Save csanz/1764649 to your computer and use it in GitHub Desktop.
How to avoid flow control libs
// example
// problem
exports.function1 = function(){
object.find(query, function(data){
object.find(query, function(data){
object.find(query, function(data){
//finally I'm here!
})
})
});
}
// what we do - more manageable
exports.function1 = function(){
object.find(query, foundData1)
function foundData1(data){
object.find(query, foundData2)
}
function foundData2(data){
object.find(query, foundData3)
}
function foundData3(data){
//finally
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment