CNode

请问EventEmitter的事件队列的大小可以修改吗

问答
LLinkXSystem发布于9 年前最后回复9 年前5 回复3859 浏览0 收藏

请问EventEmitter的事件队列的大小可以修改吗

查看回复

回复 (5)

M
MiYogurt#1·9 年前

可以,自己看 API

L
LinkXSystem#2·9 年前

可是我就是在API没看到才来问的,请问在哪,谢谢

I
i5ting#4·9 年前
引用 LinkXSystem可是我就是在API没看到才来问的,请问在哪,谢谢

@LinkXSystem

直接翻源码lib/event.js


// By default EventEmitters will print a warning if more than 10 listeners are
// added to it. This is a useful default which helps finding memory leaks.
var defaultMaxListeners = 10;

Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
  enumerable: true,
  get: function() {
    return defaultMaxListeners;
  },
  set: function(arg) {
    // force global console to be compiled.
    // see https://github.com/nodejs/node/issues/4467
    console;
    // check whether the input is a positive number (whose value is zero or
    // greater and not a NaN).
    if (typeof arg !== 'number' || arg < 0 || arg !== arg)
      throw new TypeError('"defaultMaxListeners" must be a positive number');
    defaultMaxListeners = arg;
  }
});
L
LinkXSystem#5·9 年前

@i5ting @chickencyj 按以上的回答,我疑惑的是EventEmitter的listeners 的作用就是监听的最大事件数吗 ?我所理解的是** defaultMaxListeners 指的是 emitter.on 方法所能设置的数量**,而我正在实践的问题是由emitter.emit所产生的事件(并发情况, 数量大约5000),** emitter.on** 方法最大能缓存多少事件(如果处理不过来的情况下)

参与回复
登录后即可参与回复。登录