Friday, 5 October 2018

node.js: emitter.getMaxListeners()

emitter.getMaxListeners()
Returns the current max listener value for the EventEmitter. You can set the maximum listeners for an event to the emitter by calling ‘setMaxListeners(n)’. If you do not set maximum listeners value explicitly, then the ‘EventEmitter.defaultMaxListeners’ value is used as default value.

HelloWorld.js

var EventEmitter = require('events').EventEmitter;

var emitter = new EventEmitter();

console.log("Default maximum listeners for all the emitters %d", EventEmitter.defaultMaxListeners);
console.log("Maximum listeners for the emitter %d", emitter.getMaxListeners());

//Setting maximum listeners to 20
emitter.setMaxListeners(20);
console.log("\nSet maximum listeners to 20, using 'setMaxListeners'");
console.log("Maximum listeners for the emitter %d", emitter.getMaxListeners());


Output

Default maximum listeners for all the emitters 10
Maximum listeners for the emitter 10

Set maximum listeners to 20, using 'setMaxListeners'
Maximum listeners for the emitter 20



Previous                                                 Next                                                 Home

No comments:

Post a Comment