【问题标题】:node async only calls first function when inside node-lambdanode async 仅在 node-lambda 内部调用第一个函数
【发布时间】:2016-06-02 09:17:49
【问题描述】:

使用像以下节点异步这样的普通节点脚本就可以了:

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,
  • 节点 5.5.0
  • node-lambda 0.1.5

【问题讨论】:

    标签: javascript node.js asynchronous lambda aws-lambda


    【解决方案1】:

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

    【讨论】:

    • @keithgould 我已经更新了答案。尝试删除context.done( );进行测试
    • 轰隆隆!那就是@isvforall。谢谢。
    猜你喜欢
    • 2019-11-16
    • 1970-01-01
    • 2016-06-16
    • 1970-01-01
    • 2017-09-15
    • 1970-01-01
    • 1970-01-01
    • 2021-05-22
    • 1970-01-01
    相关资源
    最近更新 更多