节点.js“已调用回调”.但是没有任何其他回调
Node.js "Callback is already called". But there are no any other callbacks
我整天都在搜索论坛,但我无法解决我的问题。我使用 NodeJS 和 async.waterfall 来发出一些 API 请求。相同的结构对我有用,但不存在;
async.waterfall([
function (callback) {
callback(null, latitude, longitude, callback);
},
getGeoNames,
],
function (err, result) {
console.log("ok");
})
这是函数 getGeoNames 有错误
function getGeoNames(latitude, longitude, callback) {
var countryKey = 'country';
var stateKey = 'administrative_area_level_1';
var url = "http://maps.googleapis.com/maps/api/geocode/json?latlng="+latitude+","+longitude;
request({
url: url,
json: true
}, function (error, response, body) {
var adresses = body.results[0].address_components;
var geo = {};
for (var i = 0, len = adresses.length; i < len; i++) {
var adress = adresses[i];
//console.log(adress);
if ( adress.types[0] == countryKey ) {
geo.country = adress.long_name;
if (geo.state !== undefined) break;
}
else if ( adress.types[0] == stateKey ) {
geo.state = adress.long_name;
if (geo.country !== undefined) break;
}
};
return callback(null, geo); // ERROR HERE <-----------------
})
}
请求函数可以运行 callback() 函数吗,所以它之前运行过?我尝试过没有"返回",但它是一样的。
if (fn === null) throw new Error("Callback was already called."); ^
错误:已调用回调。 at c:''Users''Serega'ode_modules''async''dist''async.js:803:36 at Request._callback (c:''Users''Serega''WebstormProjects''untitled1''server.js:174:20) at Request.self.callback (c:''Users''Serega'ode_modules''request''request.js:200:22) 在发出两个(事件.js:87:13) at Request.emit (events.js:172:7) 应要求。(c:''Users''Serega'ode_modules''request''request.js:1067:10) at emitOne (events.js:82:20) at Request.emit (events.js:169:7) 在来电消息。(c:''Users''Serega'ode_modules''request''request.js:988:12) at emitNone (events.js:72:20)
进程已完成,退出代码为 1
PS:其他瀑布功能适用于我的请求。
感谢您的帮助!
错误在这里。
callback(null, latitude, longitude, callback);
不应将回调作为参数传递。
- 有没有办法将其他参数传递给 scrollTarget 回调函数
- 节点.js“已调用回调”.但是没有任何其他回调
- 如何绑定'这'到react类之外的函数,后者是来自其他组件的回调
- 在其他回调js中调用回调
- 如何将回调函数包装在其他回调函数中并从中调用
- 使用其他模块中的函数,避免异步回调地狱
- jquery在html属性中添加函数回调,以便在其他事件中调用
- 无法访问回调函数中的其他函数
- E_UNKNOWN beforeCreate 和其他生命周期回调的响应错误
- 传递其他参数以过滤回调 D3 和 javascript
- 将其他参数传递到回调函数中
- 可能从其他域弹出时回调 JavaScript
- 使用此函数在回调中调用其他函数
- Javascript回调的处理速度比其他回调更快
- 我需要做什么才能让我的回调函数在其他事情之前运行
- JavaScript回调/关闭/其他
- 知道所有其他准备好的回调何时完成
- 如何通过回调或其他方式删除方法
- 当使用原型方法声明从回调访问对象时,如何访问对象的其他方法
- JavaScript:与其他变量同名的回调函数参数