Created
January 14, 2015 15:48
-
-
Save Dremora/cda95a01c5a61c8054b5 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
var input | |
// Synchronous code | |
var a_ = a(input) | |
var b_ = b(a_) | |
var output = c(b_) | |
// Synchronous code, short | |
var output = c(b(a(_))) | |
// Asynchronous code, callbacks | |
var status | |
a(input, function (err, a_) { | |
if (err) throw new Error() | |
b(a_, function (err, b_) { | |
if (err) throw new Error() | |
c(b_, function(err, c_) { | |
if (err) throw new Error() | |
output = c_ | |
}) | |
}) | |
}) | |
// Asynchronous code, promises | |
var output | |
a(input) | |
.then(function (a_) { | |
return b(a_) | |
}) | |
.then(function (b_) { | |
return c(b_) | |
}) | |
.then(function (c_) { | |
output = c_ | |
}) | |
.catch(function (err) { | |
console.error(err) | |
}) | |
// Asynchronous code, promises, short | |
a(input).then(b).then(c) | |
.then(function (c_) { | |
output = c_ | |
}) | |
.catch(function (err) { | |
console.error(err) | |
}) | |
// Asynchronous code, generators+co | |
var a_ = yield a(input) | |
var b_ = yield b(a_) | |
var output = yield c(b_) | |
// Asynchronous code, generators+co, short | |
var output = yield c(yield b(yield a(input))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment