Node.js 当在while循环中使用promise.all时,会发生MaxListenerSexceedAdwarning
我在while循环中使用promise。当执行大约50个承诺时,MaxListenerSexceedawarning警告开始发出警报。所以我想知道承诺和承诺之间有什么关系。以及如何修复我的代码以避免此警告 我试图减少contentList中的项目数。当数字低于50时,就没有警告了。但当数字超过50时,它开始发出警告Node.js 当在while循环中使用promise.all时,会发生MaxListenerSexceedAdwarning,node.js,es6-promise,Node.js,Es6 Promise,我在while循环中使用promise。当执行大约50个承诺时,MaxListenerSexceedawarning警告开始发出警报。所以我想知道承诺和承诺之间有什么关系。以及如何修复我的代码以避免此警告 我试图减少contentList中的项目数。当数字低于50时,就没有警告了。但当数字超过50时,它开始发出警告 async (req, res, next) => { let repository = new ContentRep(); let contentList
async (req, res, next) => {
let repository = new ContentRep();
let contentList = (await repository.getContentList({category: 'allContent'})).contentList;
while (contentList.length > 0) {
let taskSize = contentList.length > 5 ? 5 : contentList.length;
let subList = contentList.slice(0, taskSize);
contentList = contentList.slice(taskSize, contentList.length);
let contentPromises = [];
subList.forEach(row => {
contentPromises.push(new Promise(resolve => {
repository.getTemplateInfo(row.category, row.content)
.then(templateInfo => {
resolve(templateInfo);
});
}));
})
await Promise.all(contentPromises);
}
return contentList;
}
错误代码
(node:63176) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added. Use emitter.setMaxListeners() to increase limit
此警告通常由于内存泄漏和内部错误而出现。 增加可注册的最大事件限制将删除警告 将此代码添加到主文件中
require('events').EventEmitter.prototype._maxListeners = 100;
此警告通常由于内存泄漏和内部错误而出现。 增加可注册的最大事件限制将删除警告 将此代码添加到主文件中
require('events').EventEmitter.prototype._maxListeners = 100;
可能重复的可能重复此选项隐藏问题而不修复实际问题。此选项隐藏问题而不修复实际问题。