add another async.parallel example #114

mariusa opened this Issue Mar 13, 2012 · 6 comments


None yet
5 participants

mariusa commented Mar 13, 2012


Would it be possible please to add an example to the docs showing how to use async.parallel with a real-life use?
I simply don't get it how it should work from docs, from test/ or from

A nice example would be to read 2 files and make a db call (all these 3 in parallel, async), and then do something with all 3.

Here's a start, which I can't tell how to make it work:


rlidwka commented Mar 13, 2012

Hm... usage here is the same as in other functions basically.

Ok, that's real-world example, hope it helps:

var mongo;
var httpserv;

    function(callback) {
        var mongodb = require('mongodb');
        mongo = new mongodb.Db('project', new mongodb.Server("", 27017, {auto_reconnect: true}));;

    function(callback) {
        httpserv = require('http').createServer(function (request, response) {
            process_request(request, response);
        httpserv.listen(1337, callback);
], function() {
    Application.init(mongo, httpserv);

PS: variables should be return values of course... but you've asked about real life - how it is, not how it should be :D

Mariusa, I re-wrote your code example here:
async.parallel uses callbacks to populate the results array or object.
Someone should close this issue.


brianmaissy commented Feb 6, 2013

Anyone else feel that the example in the docs isn't clear? @mariusa do you feel that this example adds something substantial that wasn't communicated by that example? If so, we should add it to the docs. If not, @caolan should close this.


caolan commented Feb 6, 2013

I'd like the examples to be concise and clearly show the concept. I don't want them to teach JavaScript or Node.js. If people feel the underlying concept isn't described by the example then we should update it, otherwise I'll close this.


brianmaissy commented Feb 6, 2013

Judging by the initial (incorrect) example proposal by @rlidwka the misunderstanding was more an issue of higher-order functions than the usage of async.parallel. I think the example in the docs is clear.


caolan commented Feb 6, 2013

Agreed, closing.

@caolan caolan closed this Feb 6, 2013

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