Skip to content

Instantly share code, notes, and snippets.

@ashishmadeti
Created March 9, 2016 10:17
Show Gist options
  • Save ashishmadeti/f2bc4c7dbaeaeb0ec84f to your computer and use it in GitHub Desktop.
Save ashishmadeti/f2bc4c7dbaeaeb0ec84f to your computer and use it in GitHub Desktop.
Async 'auto' example for Sails.js (A framework for Node.js)
module.exports = {
feedTwoDogs: function(req, res) {
async.auto({
getDogFood: function(callback) {
food = {
tommy: 200,
lucy: 350
}
callback(null, food)
},
feedTommy: ['getDogFood', function(callback, results) {
foodForTommy = results.getDogFood.tommy
// Feed tommy
callback(null, 'tommy is full')
}],
feedLucy: ['getDogFood', function(callback, results) {
foodForTommy = results.getDogFood.lucy
// Feed lucy
callback(null, 'lucy is full')
}]
}, function(err, results) {
if (err) { return res.serverError(err) }
console.log(results)
// results = {
// getDogFood: { tommy: 200, lucy: 350 }
// feedTommy: 'tommy is full'
// feedLucy: 'lucy is full'
// }
return res.json({
status: 'Both dogs full'
})
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment