Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. /**
  2. * AWS Module: Action: Modularized Code with Promise for Asynchronous functions
  3. */
  4.  
  5. var Promise = require('bluebird');
  6.  
  7. // Export For Lambda Handler
  8. module.exports.run = function(event, context, cb) {
  9. return action(event).then(function(result) {
  10. cb(null, result);
  11. }).error(function(error) {
  12. cb(error, null);
  13. });
  14. };
  15. // Your Code
  16. var action = function(event) {
  17. return new Promise(function(resolve, reject) {
  18. // Do your thing here
  19. var asynchronousFunction = event;
  20. // Inside your asychronous callback put this:
  21. if (asynchronousFunction.succeed) {
  22. resolve('Yay!');
  23. } else {
  24. reject({error: 'Boo!'});
  25. }
  26. });
  27. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement