-
-
Save PaquitoSoft/5764478 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 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