我正在用风数据(从 API JSON 中抓取)填充一个数组,但出现错误MaxListenersExceededWarning。我已经查过了,这似乎是由于代码中的错误造成的。解决方法是设置setMaxListeners(n);,但显然不推荐这样做。
任何人都可以看到是什么导致注册了这么多听众吗?什么是解决方案?我正在创建一个在请求时吐出数组的 API windRecordings。
代码
const getWindForecast = (windRecordings) => {
setInterval(() => {
const instantWind = scrapeAPI(
"http://mobvaer.kystverket.no/v2/api/stations/5265049"
);
instantWind.then((res) => {
if (windRecordings.length > 0) {
// A wind value(s) is already pushed to the list
const latestRecordedWind = windRecordings[windRecordings.length - 1]; // get the first element out
// Compare the lates wind value in the list to the lates API request wind value
if (
latestRecordedWind[1]["Value"]["Value"] == res[1]["Value"]["Value"]
) {
console.log("They are the same");
} else {
console.log("They are not the same, push them.")
windRecordings.push(res);
}
} else {
// The length is less than 0, no element has been added so far, push element
console.log("Push the first to the list");
windRecordings.push(res);
}
});
return windRecordings;
}, 1000);
};
错误
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(node:85830) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(node:85830) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGTERM listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(node:85830) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGHUP listeners added to [process]. Use emitter.setMaxListeners() to increase limit
});
海绵宝宝撒
相关分类