Created
February 22, 2011 22:16
-
-
Save pguillory/839545 to your computer and use it in GitHub Desktop.
Revisions
-
pguillory created this gist
Feb 22, 2011 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ // Synchronous form - 6 lines function f() { a() b() c() d() } // Asynchronous form - 12 lines function f(callback) { a(function(err) { if (err) return callback(err) b(function(err) { if (err) return callback(err) c(function(err) { if (err) return callback(err) d(callback) }) }) }) } // Asynchronous form, broken into functions to limit nesting - 18 lines function f(callback) { a(function(err) { if (err) return callback(err) bcd(callback) }) } function bcd(callback) { b(function(err) { if (err) return callback(err) cd(callback) }) } function cd(callback) { c(function(err) { if (err) return callback(err) d(callback) }) }