Created
February 8, 2012 02:27
-
-
Save csanz/1764649 to your computer and use it in GitHub Desktop.
How to avoid flow control libs
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
// 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