Created
March 9, 2016 10:17
-
-
Save ashishmadeti/f2bc4c7dbaeaeb0ec84f to your computer and use it in GitHub Desktop.
Async 'auto' example for Sails.js (A framework for Node.js)
This file contains 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
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