Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node async only calls first function when inside node-lambda

Using a vanilla node script like the following node async works just fine:

async = require('async');

async.waterfall([
    function (c) {
        console.log(1);
        c(null);
    },        
    function (c) {
        console.log(2);
        c(null);
    }       
  ]);

The above when run via node test.js prints out:

1
2

... as expected.

However if I place the code inside a node-lambda handler:

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( );
}

Only the first method is called when I run ./node_modules/.bin/node-lambda run

==================================
1
==================================

I'm using:

  • async 1.5.2,
  • node 5.5.0
  • node-lambda 0.1.5
like image 576
keith gould Avatar asked Sep 18 '26 04:09

keith gould


1 Answers

You are using asynchronous code. Apparently that code context.done( ); to finish the executing of the main function handler and other async code(second function in waterfall) cannot be executed, it did not have time enough, because the main function has been completed.

like image 155
isvforall Avatar answered Sep 20 '26 19:09

isvforall