【发布时间】:2019-01-25 08:45:03
【问题描述】:
我有以下Promise.all 示例。我想知道它是否与lambda.invoke“并行”运行?我如何测试某些东西是否并行运行?
引用了这个thread
function get1(id) {
return new Promise((resolve, reject) => {
const params = {
FunctionName: 'myLambda', // the lambda function we are going to invoke
InvocationType: 'RequestResponse',
Payload: { id },
};
lambda.invoke(params, (err, data) => {
if (err) {
reject(new Error('error'));
} else {
const result = JSON.parse(data.Payload);
resolve(result);
}
});
}).catch(e => Promise.resolve({ error: 'Error has occurred.' }));
}
exports.getDetails = list => Promise.all(list.map(get1))
.then((response) => {
return result;
}).catch((error) => {
console.log('oops ', error);
});
【问题讨论】:
-
AWS SDK 可以为您返回一个承诺。只需
lambda.invoke(params).promise()。
标签: javascript node.js amazon-web-services aws-lambda