Thursday 20 April 2017

async parallel inside async for each inside async waterfall

The following is my code. I am trying to get execute async.parallel for each value of an array dates using async.foreach. However, I cant seem to make fdata available after async.forEach and async.parallel have completed. Please help.I

async.waterfall([
            function(callback_wf_one) {
                async.forEachOf(dates, function(value, index, callback_e_one) {

                    async.parallel({
                            failed: function(callback_p_one) {
                                db[collectionname].find(selector_one, function(err, docs) {
                                    if (!err) {
                                        test_a = docs.length
                                    } else {
                                        test_a = 0
                                    }
                                    callback_p_one(null, test_a);
                                });
                            },
                            success: function(callback_p_one) {
                                db[collectionname].find(selector_two, function(err, docs) {
                                    if (!err) {
                                        test_b = docs.length
                                    } else {
                                        test_b = 0
                                    }
                                    callback_p_one(null, test_b);
                                });
                            }
                        },
                        function(err, data) {
                            data = {
                                //some data
                            }
                            fdata.push(data);
                            console.log(JSON.stringify(fdata));
                            callback_e_one(null)
                        }
                    );
                });
            },
            function(fdata, callback_wf_one(null, data)) {
                    console.log(fdata);
                }

            ],
            function(err, data) {
                console.log(data)
            });



via GNU

No comments:

Post a Comment