节点asynchronous仅在node-lambda内部调用第一个函数

使用像下面的节点asynchronous的香草节点脚本工作得很好:

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 ================================== 

我在用着:

  • asynchronous1.5.2,
  • 节点5.5.0
  • 节点lambda 0.1.5

您正在使用asynchronous代码。 显然,代码context.done( ); 完成主函数handler和其他asynchronous代码的执行(瀑布中的第二个函数)不能执行,因为主函数已经完成,所以没有足够的时间。