-
-
Save jwulf/4db4fd47d23915573894 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
/** | |
* AWS Module: Action: Modularized Code with Promise for Asynchronous functions | |
*/ | |
var Promise = require('bluebird'); | |
// Export For Lambda Handler | |
module.exports.run = function(event, context, cb) { | |
return action(event).then(function(result) { | |
cb(null, result); | |
}).error(function(error) { | |
cb(error, null); | |
}); | |
}; | |
// Your Code | |
var action = function(event) { | |
return new Promise(function(resolve, reject) { | |
// Do your thing here | |
var asynchronousFunction = event; | |
// Inside your asychronous callback put this: | |
if (asynchronousFunction.succeed) { | |
resolve('Yay!'); | |
} else { | |
reject({error: 'Boo!'}); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment