2

I am using async.js for the first time and would like to seperate out the function array into seperate functions. I have:

working code

    async.waterfall([
        function(callback)
        {
            var querySuccess = function (tx, result)
            {
                callback(null, result.rows.item(0).EventImportTime || "");
            };

            var queryError = function (tx, e)
            {
                callback("Query Error")
            };

            database.open();
            database.query("SELECT EventImportTime FROM Contact WHERE Contact.Id = ?", [contactId], querySuccess, queryError);
        },
        function(lastImportTime, callback)
        {
            var url = "";
            url += 'MobileGetvents.aspx?';
            url += '&LastImportTime=';
            url +=  lastImportTime;
            url += '&Format=JSON';

            callback(null, url)
        },
    ],
    function(err, result)
    {
        if (err)
            console.log("Error Happened");
        else 
        {
            console.log(result);
            getJSON(result, callback, 

errorCallback)
            }
        })

I want

async.waterfall([
            getLastImportTime(callback) ,
            buildUrl(lastImportTime, callback),
        ],
        //callback
);

However when I run this code it always returns

Uncaught ReferenceError: lastImportTime is not defined

1 Answer 1

5

I would assume that you want this instead:

var getLastImportTime = function(callback) { };
var buildUrl = function(lastImportTime, callback) { };

async.waterfall([
            getLastImportTime,
            buildUrl,
        ],
        //callback
);
Sign up to request clarification or add additional context in comments.

4 Comments

haha learning something new can really make you overlook the obvious.
If you really want to learn something hot, you should take a look at jQuery's Deferred object and most importantly, the pipe method, you can achieve the same thing as what asych waterfall does.
believe it or not thats where this Async.js came from. I wanted to use deferred but couldnt figure it out. So i turned to Async.js
This is an excellent article I found very helpful and triggered the 'AHA' moment for me: msdn.microsoft.com/en-us/magazine/gg723713.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.