1

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.

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.