I am using Q for my promise library.
I have a promise that if success calls and array of promises.

The code is:

    getCount(client).then(function (count) {                         // 
when successful create a 
        var promises = [];                                                 
 // array of promises to be processed next
        for (var i = 0; i < count; i++) {                                 
// in order
            promises.push(az(client, i));
        }
        return Q.all(promises);
    }).then(function(results) {
            console.log("everything went right. All results:", results);
        }, function(err) {
            console.log("something (either getCount, or one of the az 
calls) blew up", err);
        });

so az takes and index and returns a value. If index === 1  it throws.

function az(client, index) {
    var xml = "<urn:mgmtISCSIGetTargetList> </urn:mgmtISCSIGetTargetList>";
    client.MgmtServer.MgmtServer.asynCall(xml, function (err, result) {

            if (err) {
                return deferred.reject(err);
            }

            if (1 === index) {
                console.log('index 1 is bad news');
                return deferred.reject("Blew up");
            }

            console.log('returning with index ' + index + ' returning ' + 
(index + 30));
            deferred.resolve(index + 30);
        }
    );
    return deferred.promise;
};

when I run this, I see this output:
everything went right. All results: [ 3, 3, 3 ]
returning with index 0 returning 30
index 1 is bad news
returning with index 2 returning 32


Output of getCount first then az 1 2 3 and the exception for 1 never 
sending me to console.log("something (either getCount, or one of the az 
calls) blew up", err);

Am I using my array of promises incorrectly?

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to