使用像下面的 Node 异步这样的普通 Node 脚本就可以正常工作:
async = require('async');
async.waterfall([
function (c) {
console.log(1);
c(null);
},
function (c) {
console.log(2);
c(null);
}
]);
以上通过 node test.js
运行时打印出:
1
2
...正如预期的那样。
但是,如果我将代码放在 node-lambda 处理程序中:
var async = require('async');
exports.handler = function( event, context ) {
console.log( "==================================");
async.waterfall([
function (c) {
console.log(1);
c(null);
},
function (c) {
console.log(2);
c(null);
}
]);
console.log( "==================================");
context.done( );
}
当我运行 ./node_modules/.bin/node-lambda run 时只调用第一个方法
==================================
1
==================================
我正在使用:
- 异步 1.5.2,
- Node 5.5.0
- Node -lambda 0.1.5
最佳答案
您正在使用异步代码。
显然,代码 context.done( );
完成主函数 handler
和其他异步代码( waterfall 中的第二个函数)的执行无法执行,它没有时间足够,因为主要功能已经完成。
关于javascript - node async 仅在 node-lambda 内部调用第一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35528365/