gpt4 book ai didi

node.js - async.js 并行无法正常工作

转载 作者:太空宇宙 更新时间:2023-11-03 22:55:05 25 4
gpt4 key购买 nike

我有以下代码:

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

这不起作用,我的控制台将回调中完成的第一个查询显示为结果。输出中也没有 {one: fullResults,two: gpsThresholds} 格式,它只是显示各个函数的回调值。

最佳答案

异步回调的第一个参数应该是错误对象,因此如果一切正常,它实际上应该返回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 传递给异步回调的错误处理程序。
documentation中有一个例子准确显示它是如何完成的。

关于node.js - async.js 并行无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20957812/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com