emitter.setMaxListeners(n)
By
default, EventEmitter allows 10 macimum listeners to an event. You can change
this behavior using 'emitter.setMaxListeners(n)' method. The value ‘n’ can be
set to Infinity (or 0) to indicate an unlimited number of listeners.
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
No comments:
Post a Comment