【发布时间】:2019-04-18 08:36:06
【问题描述】:
一旦事件完成,我想删除监听器以避免套接字 io 中的这个问题。
我收到了这个错误
MaxListenersExceededWarning:检测到可能的 EventEmitter 内存泄漏。添加了 11 个连接侦听器。使用emitter.setMaxListeners() 增加限制
我尝试过使用 removeAllListeners / removeListener / off 但它们都不起作用。
const io = socket(httpServer);
(async () => {
await io.on('connection', async function (client) {
// Some Code //
await client.emit('message', "Done")
io.removeAllListeners("connection")
})
})
【问题讨论】: