Responsive Ad Area

Share This Post

test

How to return a result object from async.waterfall that calls abstracted functions (nodejs)

I have a nodejs server hosting web services for a web app. I have a routes endpoint that lands on a nodejs function that contains an async.waterfall set of dependent function calls. The async.waterfall functions execute correctly (console.log reveals the correct result values), HOWEVER, I cannot seem to return the result as a response object to the web service call. The result is no error nor any result sent.
Is it possible to access the result objects or values that an async.waterfall produces? If so, how?

I have tried using callbacks at the module.exports level, nodejs errors out saying that the callback is not a function.

var async = require ('async');
var getheaderinfo = require('../procedures/get_object_header');
var getattributes = require('../procedures/get_object_attrs');

module.exports = function job_detail(req, res) {

var lo_data = {
    "type":null,
    "code":null,
    "id":null,
    "title":null,
    "description":null,
    "attrs":[
        {
        "id":null,
        "name":null,
        "value":null
    }
    ],
};

lo_data.type = 4;
lo_data.code = req.params.job_id;

async.waterfall([

// Get job header
    function getheader(callback) {
        getheaderinfo(lo_data, function(cb_job_header){

            lo_data.id = cb_job_header.id;
            lo_data.title = cb_job_header.title;
            lo_data.description = cb_job_header.description;

            return callback(null, cb_job_header.id);

            });
    }, // Get job detailed attribution
    function getattrs(lookupid, callback) {

        getattributes(lo_data, function(cb_job_attrs){

            lo_data.attrs[0].id = cb_job_attrs[0].id;
            lo_data.attrs[0].name = cb_job_attrs[0].name;
            lo_data.attrs[0].value = cb_job_attrs[0].value;

            return callback(null, lo_data);

        })
    }
], 
    function(err, result) {
        if (result) {
            res.end(JSON.stringify(result));
        }
    } 
);
}

I expect the result object (or lo_data object) to be able to be passed back to the angular web app that made the call and display the results in the UI.


How to return a result object from async.waterfall that calls abstracted functions (nodejs)
How to return a result object from async.waterfall that calls abstracted functions (nodejs)
test
{$excerpt:n}

Share This Post

Leave a Reply

Your email address will not be Publishedd. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Skip to toolbar