async.waterfall mechanism doesn't seem to work with another level of nested callback #130

Closed
pjdurai opened this Issue May 17, 2012 · 2 comments

Comments

Projects
None yet
4 participants

pjdurai commented May 17, 2012

Hi

I am using async in iOS using phonegap.

This is the canonical example for waterfall.

MyModule.testMe = function(event) {
async.waterfall([
function(callback){
callback(null, 'one', 'two');
},
function(arg1, arg2, callback){
callback(null, 'three');
},
function(arg1, callback){
callback(null, 'done');
}
], function (err, result) {
// result now equals 'done'
});
}

Suppose I have to call an asynchronous function in one of the array member functions, it doesn't work as I expected.

This is what I came up with. Please tell me if I am missing anything. Or is it not expected to work in such a manner?
e.g.

MyModule.testMe = function(event) {
async.waterfall([
function(callback){
object.anotherfn( function (success_result) { callback(null, success_result);}, // This doesn't work.
function(error) { callback(error));
},
function(some_result_object, callback){
callback(null, 'three');
},
function(arg1, callback){
callback(null, 'done');
}
], function (err, result) {
// result now equals 'done'
});
}

Should the 'callback' at the end of the top-level in each array member function?
Is there any way around this?

Thanks
pj

Your 'non working code' when prettified looks like this:

MyModule.testMe = function (event) {
    async.waterfall([

    function (callback) {
        object.anotherfn(function (success_result) {
            callback(null, success_result);
        }, // This doesn't work.
        function (error) {
            callback(error));
        }, function (some_result_object, callback) {
            callback(null, 'three');
        }, function (arg1, callback) {
            callback(null, 'done');
        }], function (err, result) {
        // result now equals 'done'
    });
    }

but I think it should look like this instead:

MyModule.testMe = function (event) {
    async.waterfall([

    function (callback) {
        object.anotherfn(function (success_result) {
            callback(null, success_result);
        }, // This doesn't work.
        function (error) {
            callback(error));
        });
    }, function (some_result_object, callback) {
        callback(null, 'three');
    }, function (arg1, callback) {
        callback(null, 'done');
    }], function (err, result) {
        // result now equals 'done'
    });
}

caolan closed this Mar 28, 2014

This message was created automatically by mail delivery software.

A message that you sent could not be delivered to one or more of its
recipients. This is a temporary error. The following address(es) deferred:

alizbazar@gmail.com
Domain alizweb.com has exceeded the max emails per hour (120/120 (100%)) allowed. Message will be reattempted later

------- This is a copy of the message, including all the headers. ------
Received: from github-smtp2-ext6.iad.github.net ([192.30.252.197]:40908 helo=github-smtp2b-ext-cp1-prd.iad.github.net)
by web107.webhotelli.fi with esmtps (TLSv1:DHE-RSA-AES256-SHA:256)
(Exim 4.82)
(envelope-from noreply@github.com)
id 1WTaN6-0003YD-4P
for alizbazar@alizweb.com; Fri, 28 Mar 2014 19:15:12 +0200
Date: Fri, 28 Mar 2014 10:15:11 -0700
From: Caolan McMahon notifications@github.com
Reply-To: caolan/async reply@reply.github.com
To: caolan/async async@noreply.github.com
Message-ID: caolan/async/issue/130/issue_event/106554014@github.com
In-Reply-To: caolan/async/issues/130@github.com
References: caolan/async/issues/130@github.com
Subject: Re: [async] async.waterfall mechanism doesn't seem to work with
another level of nested callback (#130)
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="--==_mimepart_5335ae1f1e363_23dc3fd1fcd332b41526b9";
charset=UTF-8
Content-Transfer-Encoding: 7bit
Precedence: list
X-GitHub-Recipient: alizbazar
List-ID: caolan/async <async.caolan.github.com>
List-Archive: https://github.com/caolan/async
List-Post: mailto:reply@reply.github.com
List-Unsubscribe: mailto:unsub+i-4618035-b5e9245d5476fc34660dd33af1b757ddd1b2933d-736771@reply.github.com,
https://github.com/notifications/unsubscribe/736771__eyJzY29wZSI6Ik5ld3NpZXM6TXV0ZSIsImV4cGlyZXMiOjE3MTE2NDYxMTEsImRhdGEiOnsiaWQiOjUzNjA3M319--7a3a60b55efcbe72735bd8c26bb8388263e80702
X-Auto-Response-Suppress: All
X-GitHub-Recipient-Address: alizbazar@alizweb.com

----==_mimepart_5335ae1f1e363_23dc3fd1fcd332b41526b9
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit

Closed #130.


Reply to this email directly or view it on GitHub:
#130
----==_mimepart_5335ae1f1e363_23dc3fd1fcd332b41526b9
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit

Closed #130.


Reply to this email directly or view it on GitHub.

----==_mimepart_5335ae1f1e363_23dc3fd1fcd332b41526b9--

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment