2
"source": "doc/api/events.markdown",
8
"stabilityText": "API Frozen",
10
"desc": "<p>Many objects in Node emit events: a <code>net.Server</code> emits an event each time\na peer connects to it, a <code>fs.readStream</code> emits an event when the file is\nopened. All objects which emit events are instances of <code>events.EventEmitter</code>.\nYou can access this module by doing: <code>require("events");</code>\n\n</p>\n<p>Typically, event names are represented by a camel-cased string, however,\nthere aren't any strict restrictions on that, as any string will be accepted.\n\n</p>\n<p>Functions can then be attached to objects, to be executed when an event\nis emitted. These functions are called <em>listeners</em>.\n\n\n</p>\n",
13
"textRaw": "Class: events.EventEmitter",
15
"name": "events.EventEmitter",
16
"desc": "<p>To access the EventEmitter class, <code>require('events').EventEmitter</code>.\n\n</p>\n<p>When an <code>EventEmitter</code> instance experiences an error, the typical action is\nto emit an <code>'error'</code> event. Error events are treated as a special case in node.\nIf there is no listener for it, then the default action is to print a stack\ntrace and exit the program.\n\n</p>\n<p>All EventEmitters emit the event <code>'newListener'</code> when new listeners are\nadded.\n\n</p>\n",
19
"textRaw": "emitter.addListener(event, listener)",
21
"name": "addListener",
22
"desc": "<p>Adds a listener to the end of the listeners array for the specified event.\n\n</p>\n<pre><code>server.on('connection', function (stream) {\n console.log('someone connected!');\n});</code></pre>\n",
47
"textRaw": "emitter.on(event, listener)",
50
"desc": "<p>Adds a listener to the end of the listeners array for the specified event.\n\n</p>\n<pre><code>server.on('connection', function (stream) {\n console.log('someone connected!');\n});</code></pre>\n",
65
"textRaw": "emitter.once(event, listener)",
68
"desc": "<p>Adds a <strong>one time</strong> listener for the event. This listener is\ninvoked only the next time the event is fired, after which\nit is removed.\n\n</p>\n<pre><code>server.once('connection', function (stream) {\n console.log('Ah, we have our first user!');\n});</code></pre>\n",
83
"textRaw": "emitter.removeListener(event, listener)",
85
"name": "removeListener",
86
"desc": "<p>Remove a listener from the listener array for the specified event.\n<strong>Caution</strong>: changes array indices in the listener array behind the listener.\n\n</p>\n<pre><code>var callback = function(stream) {\n console.log('someone connected!');\n};\nserver.on('connection', callback);\n// ...\nserver.removeListener('connection', callback);</code></pre>\n",
101
"textRaw": "emitter.removeAllListeners([event])",
103
"name": "removeAllListeners",
104
"desc": "<p>Removes all listeners, or those of the specified event.\n\n\n</p>\n",
117
"textRaw": "emitter.setMaxListeners(n)",
119
"name": "setMaxListeners",
120
"desc": "<p>By default EventEmitters will print a warning if more than 10 listeners are\nadded for a particular event. This is a useful default which helps finding memory leaks.\nObviously not all Emitters should be limited to 10. This function allows\nthat to be increased. Set to zero for unlimited.\n\n\n</p>\n",
132
"textRaw": "emitter.listeners(event)",
135
"desc": "<p>Returns an array of listeners for the specified event. This array can be\nmanipulated, e.g. to remove listeners.\n\n</p>\n<pre><code>server.on('connection', function (stream) {\n console.log('someone connected!');\n});\nconsole.log(util.inspect(server.listeners('connection'))); // [ [Function] ]</code></pre>\n",
147
"textRaw": "emitter.emit(event, [arg1], [arg2], [...])",
150
"desc": "<p>Execute each of the listeners in order with the supplied arguments.\n\n</p>\n",
176
"textRaw": "Event: 'newListener'",
178
"name": "newListener",
180
"desc": "<p>This event is emitted any time someone adds a new listener.\n</p>\n"