async.js 并行无法正常工作

问题描述 投票:0回答:2

我有以下代码:

               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++;      
                });

这不起作用,我的控制台将回调中完成的第一个查询显示为

results
。输出中也没有
{one: fullResults, two: gpsThresholds}
格式,它只是显示各个函数的回调值。

node.js async.js
2个回答
4
投票

异步回调的第一个参数应该是错误对象,因此如果一切正常,它应该真正返回

null

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++; });

回调也是如此

callback(null, fullResults);

等等,将

null

 传递给异步回调的错误处理程序。

文档中有一个示例准确地展示了它是如何完成的。


0
投票
请确保您使用的API路径不应该有任何返回..我在像这样调用API后解决了这个问题... 请不要,我在当地工作时遇到了这个问题

fetchLearnMoreProxy: (isoCode, langCode) => `http://localhost:3001/api?url=${hostName}/api/abc/cde?country=${isoCode}&language=${langCode}`,
如有任何问题请告诉我。

© www.soinside.com 2019 - 2024. All rights reserved.