Skip to content

Instantly share code, notes, and snippets.

@PaquitoSoft
Forked from jbgutierrez/gist:5764369
Last active December 18, 2015 09:49
Show Gist options
  • Save PaquitoSoft/5764478 to your computer and use it in GitHub Desktop.
Save PaquitoSoft/5764478 to your computer and use it in GitHub Desktop.
var step = 0;
async.waterfall([
function (next){
step = 1;
getJson('/user', function(user) { next(null, user); });
},
function (user, next){
step = 2;
getJson('/twitter_profile', user.twitterId, function(twitterProfile) { next(null, user, twitterProfile); });
},
function (user, twitterProfile, next){
step = 3;
getJson('/mashup_data', user.mashupRole, twitterProfile.lastTweetTimestamp, function(data) { next(null, user, twitterProfile, mashupData); });
}
], function (user, twitterProfile, mashupData) {
if (err) {
console.log("Died at step:" + step);
} else {
console.dir({
user: user,
twitterProfile: twitterProfile,
mashupData: mashupData
});
}
});
// vs:
// see: https://gist.github.com/creationix/5544019
run(function* () {
var user, twitterProfile, mashupData, step = 1;
try {
step++;
user = yield getJson('/user');
step++;
twitterProfile = yield getJson('/tiwtter_profile', user.id);
step++;
mashupData = yield getJson('/stock_exchange', user.mashupRole, twitterProfile.lastTweetTimestamp);
console.dir({
user: user,
twitterProfile: twitterProfile,
mashupData: mashupData
});
} catch(err) {
console.log("Died at step:" + step);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment