Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

EventEmitter.setMaxListeners

Wolfy87 edited this page Nov 5, 2011 · 1 revision

About

Sets the max listener count for the EventEmitter. When the count of listeners for an event exceeds this limit a warning will be printed. Set to 0 for no limit. The default limit is 10.

Arguments

EventEmitter.setMaxListeners(maxListeners);

  • Number maxListeners The new max listener limit

Returns

Object The current EventEmitter instance to allow chaining

Notes

The warning will only be shown once, it will appear in the console. You can check if a warning has already been shown with the following code.

ee._events.{event type}.warned;

Obviously replace {event type} with a string such as speak.

Examples

var ee = new EventEmitter(),
    i = null;

for(i = 0; i < 100; i += 1) {
    ee.on('foo', function() {
        // Empty function
    });
}

// This will be logged:
// Possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.