Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: async.parallel results order #161

Closed
AaronAcerboni opened this issue Aug 2, 2012 · 3 comments
Closed

Question: async.parallel results order #161

AaronAcerboni opened this issue Aug 2, 2012 · 3 comments

Comments

@AaronAcerboni
Copy link

I understand that the async.parallel method run its task functions in parallel. However I am unsure about the order of the results.

Is the order of the results array dependant on:


When the parallel tasks callback. The first task to callback will have its results first in the final results array.

or

The order of the tasks were supplied in the async.parrallel method. The first task method will have its result first in the final results array.

@AaronAcerboni
Copy link
Author

Nevermind.

I can personally conclude that the 2nd instance is the correct one.

As clarified at the bottom of this example found in the README:

async.parallel([
    function(callback){
        setTimeout(function(){
            callback(null, 'one');
        }, 200);
    },
    function(callback){
        setTimeout(function(){
            callback(null, 'two');
        }, 100);
    },
],
// optional callback
function(err, results){
    // the results array will equal ['one','two'] even though
    // the second function had a shorter timeout.
});

@davisjam
Copy link

This should be explicitly stated in the async docs.

@davidcarma
Copy link

Another help would be possibility for a way to pass a key to use in the array lookup in the final results array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants