Pergunta

I have the following code:

               async.parallel({
                    one: function(callback) { gps_helper.get_gps(PEMSID, conn, start, stop, function(fullResults){
                        callback(fullResults);
                    }) },     //query for new dataSet
                    two: function(callback) { admin.getTh(function(gpsThresholds){
                        callback(gpsThresholds);
                    }) }
                },                                      
                function(results){

                    console.log(results);
                    console.log('emitting GPS...');
                    socket.emit('GPS', {gpsResults: results.one, thresholds: results.two, PEMSID: PEMSID, count: count, length: PEMSToDisplay.length, checked: checked});     
                    count++;      
                });

This isn't working, my console displays the first query that finishes in the callback as results. There also is no {one: fullResults, two: gpsThresholds} formatting in the output, it's just displaying the callback value form the respective functions.

Foi útil?

Solução

The first argument of the async callback should be the error object, so it should really be returning null if everything was ok

function(err, results){
     console.log(results);
     console.log('emitting GPS...');
     socket.emit('GPS', {gpsResults: results.one, thresholds: results.two, PEMSID: PEMSID, count: count, length: PEMSToDisplay.length, checked: checked});     
     count++;      
 });

same goes for the callbacks

callback(null, fullResults);

etc, to pass null to the error handler the async callback.
There's an example in the documentation showing exactly how it's done.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top