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/5764451 to your computer and use it in GitHub Desktop.
Save PaquitoSoft/5764451 to your computer and use it in GitHub Desktop.
var step = 0;
async.series([
function (next){
step = 1;
getJson('/country', function(data) { next(null, data); });
},
function (country, next){
step = 2;
getJson('/weather', function(data) { next(null, data); });
},
function (country, weather, next){
step = 3;
getJson('/stock_exchange', function(data) { next(null, data); });
}
], function (err, data) {
if (err) {
console.log("Died at step:" + step);
} else {
console.dir({
country: data[0],
weather: data[1],
stockExchange: data[2]
});
}
});
// vs:
// see: https://gist.github.com/creationix/5544019
run(function* () {
var country, weather, stockExchange, step = 1;
try {
step++;
country = yield getJson('/country');
step++;
weather = yield getJson('/weather');
step++;
stockExchange = yield getJson('/stock_exchange');
console.dir({
country: country,
weather: weather,
stockExchange: stockExchange
});
} 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