【发布时间】:2016-02-17 00:52:44
【问题描述】:
无服务器框架模块是否可以在返回之前等待承诺的“解决”?
我知道 promise 本身无法做到这一点,但是不同的框架/库(express、Jasmine、hapijs 等)通过定义何时返回的方法来解决这个问题。我需要这样的东西:
let http = require('http'),
Promise = require('bluebird');
let action = (done) => {
return new Promise((resolve, reject) => {
http
.get('http://domain.com', resolve.bind({}, 'all good!'))
.on('error', reject.bind({}, 'all wrong!'));
})
.then((response) => {
console.log('Result', response);
return done(response); // <----------- I wan't to see this as the response
// of the lambda function
});
};
module.exports.run = (event, context, cb) => cb(null, action(done));
【问题讨论】:
标签: ecmascript-6 bluebird aws-lambda aws-api-gateway serverless-framework