Skip to content

Instantly share code, notes, and snippets.

@rotemtam
Created August 18, 2016 10:07
Show Gist options
  • Save rotemtam/8341c06c38455bf1acdf271db1f3e96c to your computer and use it in GitHub Desktop.
Save rotemtam/8341c06c38455bf1acdf271db1f3e96c to your computer and use it in GitHub Desktop.
LambdaRunner - interface between ES6 generators and lambda functions
'use strict';
const co = require('co');
module.exports = function(lambda) {
return function(e, ctx, cb) {
co(
function* () {
let result = yield lambda(e, ctx);
if (cb) {
cb(null, result)
}
ctx.succeed(result);
}
)
.catch(
function(err){
let re = /Not found:/, msg;
if( err && re.test(err)) {
msg = err.message || err || "Not found: could not find resource";
} else {
msg = `Error: ${err.message || 'Internal error'}`
}
ctx.fail(msg);
if(cb) {
cb(err)
}
}
);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment