-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_internal_.EventEmitter-1.html
213 lines (213 loc) · 130 KB
/
_internal_.EventEmitter-1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<!DOCTYPE html><html class="default"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>EventEmitter | promise-priority-queue - v6.0.4</title><meta name="description" content="Documentation for promise-priority-queue - v6.0.4"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script async src="../assets/search.js" id="search-script"></script></head><body><script>document.body.classList.add(localStorage.getItem("tsd-theme") || "os")</script><header><div class="tsd-page-toolbar"><div class="container"><div class="table-wrap"><div class="table-cell" id="tsd-search" data-base=".."><div class="field"><label for="tsd-search-field" class="tsd-widget search no-caption">Search</label><input type="text" id="tsd-search-field"/></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">promise-priority-queue - v6.0.4</a></div><div class="table-cell" id="tsd-widgets"><div id="tsd-filter"><a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a><div class="tsd-filter-group"><div class="tsd-select" id="tsd-filter-visibility"><span class="tsd-select-label">All</span><ul class="tsd-select-list"><li data-value="public">Public</li><li data-value="protected">Public/Protected</li><li data-value="private" class="selected">All</li></ul></div> <input type="checkbox" id="tsd-filter-inherited" checked/><label class="tsd-widget" for="tsd-filter-inherited">Inherited</label><input type="checkbox" id="tsd-filter-externals" checked/><label class="tsd-widget" for="tsd-filter-externals">Externals</label></div></div><a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a></div></div></div></div><div class="tsd-page-title"><div class="container"><ul class="tsd-breadcrumb"><li><a href="../modules.html">promise-priority-queue - v6.0.4</a></li><li><a href="../modules/_internal_.html"><internal></a></li><li><a href="_internal_.EventEmitter-1.html">EventEmitter</a></li></ul><h1>Class EventEmitter</h1></div></div></header><div class="container container-main"><div class="row"><div class="col-8 col-content"><section class="tsd-panel tsd-comment"><div class="tsd-comment tsd-typography"><div class="lead">
<p>The <code>EventEmitter</code> class is defined and exposed by the <code>events</code> module:</p>
</div><div><pre><code class="language-js"><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">EventEmitter</span><span class="hl-0"> = </span><span class="hl-7">require</span><span class="hl-0">(</span><span class="hl-3">'events'</span><span class="hl-0">);</span>
</code></pre>
<p>All <code>EventEmitter</code>s emit the event <code>'newListener'</code> when new listeners are
added and <code>'removeListener'</code> when existing listeners are removed.</p>
<p>It supports the following option:</p>
</div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v0.1.26</p>
</dd></dl></div></section><section class="tsd-panel tsd-hierarchy"><h3>Hierarchy</h3><ul class="tsd-hierarchy"><li><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="../interfaces/_internal_.EventEmitter-2.html" class="tsd-signature-type" data-tsd-kind="Interface">EventEmitter</a><ul class="tsd-hierarchy"><li><span class="target">EventEmitter</span></li></ul></li></ul></section><section class="tsd-panel-group tsd-index-group"><h2>Index</h2><section class="tsd-panel tsd-index-panel"><div class="tsd-index-content"><section class="tsd-index-section tsd-is-inherited tsd-is-external"><h3>Constructors</h3><ul class="tsd-index-list"><li class="tsd-kind-constructor tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#constructor" class="tsd-kind-icon">constructor</a></li></ul></section><section class="tsd-index-section tsd-is-external"><h3>Properties</h3><ul class="tsd-index-list"><li class="tsd-kind-property tsd-parent-kind-class tsd-is-static tsd-is-external"><a href="_internal_.EventEmitter-1.html#captureRejectionSymbol" class="tsd-kind-icon">capture<wbr/>Rejection<wbr/>Symbol</a></li><li class="tsd-kind-property tsd-parent-kind-class tsd-is-static tsd-is-external"><a href="_internal_.EventEmitter-1.html#captureRejections" class="tsd-kind-icon">capture<wbr/>Rejections</a></li><li class="tsd-kind-property tsd-parent-kind-class tsd-is-static tsd-is-external"><a href="_internal_.EventEmitter-1.html#defaultMaxListeners" class="tsd-kind-icon">default<wbr/>Max<wbr/>Listeners</a></li><li class="tsd-kind-property tsd-parent-kind-class tsd-is-static tsd-is-external"><a href="_internal_.EventEmitter-1.html#errorMonitor" class="tsd-kind-icon">error<wbr/>Monitor</a></li></ul></section><section class="tsd-index-section tsd-is-external"><h3>Methods</h3><ul class="tsd-index-list"><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#addListener" class="tsd-kind-icon">add<wbr/>Listener</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#emit" class="tsd-kind-icon">emit</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#eventNames" class="tsd-kind-icon">event<wbr/>Names</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#getMaxListeners" class="tsd-kind-icon">get<wbr/>Max<wbr/>Listeners</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#listenerCount" class="tsd-kind-icon">listener<wbr/>Count</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#listeners" class="tsd-kind-icon">listeners</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#off" class="tsd-kind-icon">off</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#on" class="tsd-kind-icon">on</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#once" class="tsd-kind-icon">once</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#prependListener" class="tsd-kind-icon">prepend<wbr/>Listener</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#prependOnceListener" class="tsd-kind-icon">prepend<wbr/>Once<wbr/>Listener</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#rawListeners" class="tsd-kind-icon">raw<wbr/>Listeners</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#removeAllListeners" class="tsd-kind-icon">remove<wbr/>All<wbr/>Listeners</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#removeListener" class="tsd-kind-icon">remove<wbr/>Listener</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#setMaxListeners" class="tsd-kind-icon">set<wbr/>Max<wbr/>Listeners</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-static tsd-is-external"><a href="_internal_.EventEmitter-1.html#getEventListeners" class="tsd-kind-icon">get<wbr/>Event<wbr/>Listeners</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external"><a href="_internal_.EventEmitter-1.html#listenerCount-1" class="tsd-kind-icon">listener<wbr/>Count</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external"><a href="_internal_.EventEmitter-1.html#on-1" class="tsd-kind-icon">on</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external"><a href="_internal_.EventEmitter-1.html#once-1" class="tsd-kind-icon">once</a></li></ul></section></div></section></section><section class="tsd-panel-group tsd-member-group tsd-is-inherited tsd-is-external"><h2>Constructors</h2><section class="tsd-panel tsd-member tsd-kind-constructor tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a id="constructor" class="tsd-anchor"></a><h3 class="tsd-anchor-link">constructor<a href="#constructor" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-constructor tsd-parent-kind-class tsd-is-inherited tsd-is-external"><li class="tsd-signature tsd-kind-icon">new <wbr/>Event<wbr/>Emitter<span class="tsd-signature-symbol">(</span>options<span class="tsd-signature-symbol">?: </span><a href="../interfaces/_internal_.EventEmitterOptions.html" class="tsd-signature-type" data-tsd-kind="Interface">EventEmitterOptions</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="_internal_.EventEmitter-1.html" class="tsd-signature-type" data-tsd-kind="Class">EventEmitter</a></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><p>Inherited from NodeJS.EventEmitter.constructor</p><ul><li>Defined in node_modules/@types/node/events.d.ts:74</li></ul></aside><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5><span class="tsd-flag ts-flagOptional">Optional</span> options: <a href="../interfaces/_internal_.EventEmitterOptions.html" class="tsd-signature-type" data-tsd-kind="Interface">EventEmitterOptions</a></h5></li></ul><h4 class="tsd-returns-title">Returns <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="_internal_.EventEmitter-1.html" class="tsd-signature-type" data-tsd-kind="Class">EventEmitter</a></h4></li></ul></section></section><section class="tsd-panel-group tsd-member-group tsd-is-external"><h2>Properties</h2><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-static tsd-is-external"><a id="captureRejectionSymbol" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span class="tsd-flag ts-flagStatic">Static</span> <span class="tsd-flag ts-flagReadonly">Readonly</span> capture<wbr/>Rejection<wbr/>Symbol<a href="#captureRejectionSymbol" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">capture<wbr/>Rejection<wbr/>Symbol<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">typeof </span><a href="_internal_.EventEmitter-1.html#captureRejectionSymbol" class="tsd-signature-type" data-tsd-kind="Property">captureRejectionSymbol</a></div><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/events.d.ts:273</li></ul></aside></section><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-static tsd-is-external"><a id="captureRejections" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span class="tsd-flag ts-flagStatic">Static</span> capture<wbr/>Rejections<a href="#captureRejections" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">capture<wbr/>Rejections<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span></div><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/events.d.ts:278</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Sets or gets the default captureRejection value for all emitters.</p>
</div></div></section><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-static tsd-is-external"><a id="defaultMaxListeners" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span class="tsd-flag ts-flagStatic">Static</span> default<wbr/>Max<wbr/>Listeners<a href="#defaultMaxListeners" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">default<wbr/>Max<wbr/>Listeners<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/events.d.ts:279</li></ul></aside></section><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-static tsd-is-external"><a id="errorMonitor" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span class="tsd-flag ts-flagStatic">Static</span> <span class="tsd-flag ts-flagReadonly">Readonly</span> error<wbr/>Monitor<a href="#errorMonitor" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">error<wbr/>Monitor<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">typeof </span><a href="_internal_.EventEmitter-1.html#errorMonitor" class="tsd-signature-type" data-tsd-kind="Property">errorMonitor</a></div><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/events.d.ts:272</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>This symbol shall be used to install a listener for only monitoring <code>'error'</code>
events. Listeners installed using this symbol are called before the regular
<code>'error'</code> listeners are called.</p>
</div><div><p>Installing a listener using this symbol does not change the behavior once an
<code>'error'</code> event is emitted, therefore the process will still crash if no
regular <code>'error'</code> listener is installed.</p>
</div></div></section></section><section class="tsd-panel-group tsd-member-group tsd-is-external"><h2>Methods</h2><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a id="addListener" class="tsd-anchor"></a><h3 class="tsd-anchor-link">add<wbr/>Listener<a href="#addListener" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><li class="tsd-signature tsd-kind-icon">add<wbr/>Listener<span class="tsd-signature-symbol">(</span>eventName<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span>, listener<span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> => </span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="_internal_.EventEmitter-1.html" class="tsd-signature-type" data-tsd-kind="Class">EventEmitter</a></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/_internal_.EventEmitter-2.html">EventEmitter</a>.<a href="../interfaces/_internal_.EventEmitter-2.html#addListener">addListener</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:299</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Alias for <code>emitter.on(eventName, listener)</code>.</p>
</div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v0.1.26</p>
</dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>eventName: <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span></h5></li><li><h5>listener: <span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> => </span><span class="tsd-signature-type">void</span></h5><ul class="tsd-parameters"><li class="tsd-parameter-signature"><ul class="tsd-signatures tsd-kind-type-literal tsd-is-external"><li class="tsd-signature tsd-kind-icon"><span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5><span class="tsd-flag ts-flagRest">Rest</span> <span class="tsd-signature-symbol">...</span>args: <span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4></li></ul></li></ul></li></ul><h4 class="tsd-returns-title">Returns <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="_internal_.EventEmitter-1.html" class="tsd-signature-type" data-tsd-kind="Class">EventEmitter</a></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a id="emit" class="tsd-anchor"></a><h3 class="tsd-anchor-link">emit<a href="#emit" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><li class="tsd-signature tsd-kind-icon">emit<span class="tsd-signature-symbol">(</span>eventName<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span>, <span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/_internal_.EventEmitter-2.html">EventEmitter</a>.<a href="../interfaces/_internal_.EventEmitter-2.html#emit">emit</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:555</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Synchronously calls each of the listeners registered for the event named<code>eventName</code>, in the order they were registered, passing the supplied arguments
to each.</p>
</div><div><p>Returns <code>true</code> if the event had listeners, <code>false</code> otherwise.</p>
<pre><code class="language-js"><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">EventEmitter</span><span class="hl-0"> = </span><span class="hl-7">require</span><span class="hl-0">(</span><span class="hl-3">'events'</span><span class="hl-0">);</span><br/><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">myEmitter</span><span class="hl-0"> = </span><span class="hl-4">new</span><span class="hl-0"> </span><span class="hl-7">EventEmitter</span><span class="hl-0">();</span><br/><br/><span class="hl-8">// First listener</span><br/><span class="hl-2">myEmitter</span><span class="hl-0">.</span><span class="hl-7">on</span><span class="hl-0">(</span><span class="hl-3">'event'</span><span class="hl-0">, </span><span class="hl-4">function</span><span class="hl-0"> </span><span class="hl-7">firstListener</span><span class="hl-0">() {</span><br/><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">'Helloooo! first listener'</span><span class="hl-0">);</span><br/><span class="hl-0">});</span><br/><span class="hl-8">// Second listener</span><br/><span class="hl-2">myEmitter</span><span class="hl-0">.</span><span class="hl-7">on</span><span class="hl-0">(</span><span class="hl-3">'event'</span><span class="hl-0">, </span><span class="hl-4">function</span><span class="hl-0"> </span><span class="hl-7">secondListener</span><span class="hl-0">(</span><span class="hl-2">arg1</span><span class="hl-0">, </span><span class="hl-2">arg2</span><span class="hl-0">) {</span><br/><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">`event with parameters </span><span class="hl-4">${</span><span class="hl-2">arg1</span><span class="hl-4">}</span><span class="hl-3">, </span><span class="hl-4">${</span><span class="hl-2">arg2</span><span class="hl-4">}</span><span class="hl-3"> in second listener`</span><span class="hl-0">);</span><br/><span class="hl-0">});</span><br/><span class="hl-8">// Third listener</span><br/><span class="hl-2">myEmitter</span><span class="hl-0">.</span><span class="hl-7">on</span><span class="hl-0">(</span><span class="hl-3">'event'</span><span class="hl-0">, </span><span class="hl-4">function</span><span class="hl-0"> </span><span class="hl-7">thirdListener</span><span class="hl-0">(...</span><span class="hl-2">args</span><span class="hl-0">) {</span><br/><span class="hl-0"> </span><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">parameters</span><span class="hl-0"> = </span><span class="hl-2">args</span><span class="hl-0">.</span><span class="hl-7">join</span><span class="hl-0">(</span><span class="hl-3">', '</span><span class="hl-0">);</span><br/><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">`event with parameters </span><span class="hl-4">${</span><span class="hl-2">parameters</span><span class="hl-4">}</span><span class="hl-3"> in third listener`</span><span class="hl-0">);</span><br/><span class="hl-0">});</span><br/><br/><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-2">myEmitter</span><span class="hl-0">.</span><span class="hl-7">listeners</span><span class="hl-0">(</span><span class="hl-3">'event'</span><span class="hl-0">));</span><br/><br/><span class="hl-2">myEmitter</span><span class="hl-0">.</span><span class="hl-7">emit</span><span class="hl-0">(</span><span class="hl-3">'event'</span><span class="hl-0">, </span><span class="hl-6">1</span><span class="hl-0">, </span><span class="hl-6">2</span><span class="hl-0">, </span><span class="hl-6">3</span><span class="hl-0">, </span><span class="hl-6">4</span><span class="hl-0">, </span><span class="hl-6">5</span><span class="hl-0">);</span><br/><br/><span class="hl-8">// Prints:</span><br/><span class="hl-8">// [</span><br/><span class="hl-8">// [Function: firstListener],</span><br/><span class="hl-8">// [Function: secondListener],</span><br/><span class="hl-8">// [Function: thirdListener]</span><br/><span class="hl-8">// ]</span><br/><span class="hl-8">// Helloooo! first listener</span><br/><span class="hl-8">// event with parameters 1, 2 in second listener</span><br/><span class="hl-8">// event with parameters 1, 2, 3, 4, 5 in third listener</span>
</code></pre>
</div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v0.1.26</p>
</dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>eventName: <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span></h5></li><li><h5><span class="tsd-flag ts-flagRest">Rest</span> <span class="tsd-signature-symbol">...</span>args: <span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a id="eventNames" class="tsd-anchor"></a><h3 class="tsd-anchor-link">event<wbr/>Names<a href="#eventNames" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><li class="tsd-signature tsd-kind-icon">event<wbr/>Names<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">(</span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">[]</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/_internal_.EventEmitter-2.html">EventEmitter</a>.<a href="../interfaces/_internal_.EventEmitter-2.html#eventNames">eventNames</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:614</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Returns an array listing the events for which the emitter has registered
listeners. The values in the array are strings or <code>Symbol</code>s.</p>
</div><div><pre><code class="language-js"><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">EventEmitter</span><span class="hl-0"> = </span><span class="hl-7">require</span><span class="hl-0">(</span><span class="hl-3">'events'</span><span class="hl-0">);</span><br/><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">myEE</span><span class="hl-0"> = </span><span class="hl-4">new</span><span class="hl-0"> </span><span class="hl-7">EventEmitter</span><span class="hl-0">();</span><br/><span class="hl-2">myEE</span><span class="hl-0">.</span><span class="hl-7">on</span><span class="hl-0">(</span><span class="hl-3">'foo'</span><span class="hl-0">, () </span><span class="hl-4">=></span><span class="hl-0"> {});</span><br/><span class="hl-2">myEE</span><span class="hl-0">.</span><span class="hl-7">on</span><span class="hl-0">(</span><span class="hl-3">'bar'</span><span class="hl-0">, () </span><span class="hl-4">=></span><span class="hl-0"> {});</span><br/><br/><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">sym</span><span class="hl-0"> = </span><span class="hl-9">Symbol</span><span class="hl-0">(</span><span class="hl-3">'symbol'</span><span class="hl-0">);</span><br/><span class="hl-2">myEE</span><span class="hl-0">.</span><span class="hl-7">on</span><span class="hl-0">(</span><span class="hl-2">sym</span><span class="hl-0">, () </span><span class="hl-4">=></span><span class="hl-0"> {});</span><br/><br/><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-2">myEE</span><span class="hl-0">.</span><span class="hl-7">eventNames</span><span class="hl-0">());</span><br/><span class="hl-8">// Prints: [ 'foo', 'bar', Symbol(symbol) ]</span>
</code></pre>
</div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v6.0.0</p>
</dd></dl></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-symbol">(</span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">[]</span></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a id="getMaxListeners" class="tsd-anchor"></a><h3 class="tsd-anchor-link">get<wbr/>Max<wbr/>Listeners<a href="#getMaxListeners" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><li class="tsd-signature tsd-kind-icon">get<wbr/>Max<wbr/>Listeners<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/_internal_.EventEmitter-2.html">EventEmitter</a>.<a href="../interfaces/_internal_.EventEmitter-2.html#getMaxListeners">getMaxListeners</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:471</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Returns the current max listener value for the <code>EventEmitter</code> which is either
set by <code>emitter.setMaxListeners(n)</code> or defaults to <a href="_internal_.EventEmitter-1.html#defaultMaxListeners">defaultMaxListeners</a>.</p>
</div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v1.0.0</p>
</dd></dl></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">number</span></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a id="listenerCount" class="tsd-anchor"></a><h3 class="tsd-anchor-link">listener<wbr/>Count<a href="#listenerCount" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><li class="tsd-signature tsd-kind-icon">listener<wbr/>Count<span class="tsd-signature-symbol">(</span>eventName<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/_internal_.EventEmitter-2.html">EventEmitter</a>.<a href="../interfaces/_internal_.EventEmitter-2.html#listenerCount">listenerCount</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:561</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Returns the number of listeners listening to the event named <code>eventName</code>.</p>
</div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v3.2.0</p>
</dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>eventName: <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
<p>The name of the event being listened for</p>
</div></div></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">number</span></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a id="listeners" class="tsd-anchor"></a><h3 class="tsd-anchor-link">listeners<a href="#listeners" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><li class="tsd-signature tsd-kind-icon">listeners<span class="tsd-signature-symbol">(</span>eventName<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Function</span><span class="tsd-signature-symbol">[]</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/_internal_.EventEmitter-2.html">EventEmitter</a>.<a href="../interfaces/_internal_.EventEmitter-2.html#listeners">listeners</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:484</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Returns a copy of the array of listeners for the event named <code>eventName</code>.</p>
</div><div><pre><code class="language-js"><span class="hl-2">server</span><span class="hl-0">.</span><span class="hl-7">on</span><span class="hl-0">(</span><span class="hl-3">'connection'</span><span class="hl-0">, (</span><span class="hl-2">stream</span><span class="hl-0">) </span><span class="hl-4">=></span><span class="hl-0"> {</span><br/><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">'someone connected!'</span><span class="hl-0">);</span><br/><span class="hl-0">});</span><br/><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-2">util</span><span class="hl-0">.</span><span class="hl-7">inspect</span><span class="hl-0">(</span><span class="hl-2">server</span><span class="hl-0">.</span><span class="hl-7">listeners</span><span class="hl-0">(</span><span class="hl-3">'connection'</span><span class="hl-0">)));</span><br/><span class="hl-8">// Prints: [ [Function] ]</span>
</code></pre>
</div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v0.1.26</p>
</dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>eventName: <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Function</span><span class="tsd-signature-symbol">[]</span></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a id="off" class="tsd-anchor"></a><h3 class="tsd-anchor-link">off<a href="#off" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><li class="tsd-signature tsd-kind-icon">off<span class="tsd-signature-symbol">(</span>eventName<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span>, listener<span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> => </span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="_internal_.EventEmitter-1.html" class="tsd-signature-type" data-tsd-kind="Class">EventEmitter</a></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/_internal_.EventEmitter-2.html">EventEmitter</a>.<a href="../interfaces/_internal_.EventEmitter-2.html#off">off</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:444</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Alias for <code>emitter.removeListener()</code>.</p>
</div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v10.0.0</p>
</dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>eventName: <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span></h5></li><li><h5>listener: <span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> => </span><span class="tsd-signature-type">void</span></h5><ul class="tsd-parameters"><li class="tsd-parameter-signature"><ul class="tsd-signatures tsd-kind-type-literal tsd-is-external"><li class="tsd-signature tsd-kind-icon"><span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5><span class="tsd-flag ts-flagRest">Rest</span> <span class="tsd-signature-symbol">...</span>args: <span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4></li></ul></li></ul></li></ul><h4 class="tsd-returns-title">Returns <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="_internal_.EventEmitter-1.html" class="tsd-signature-type" data-tsd-kind="Class">EventEmitter</a></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a id="on" class="tsd-anchor"></a><h3 class="tsd-anchor-link">on<a href="#on" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><li class="tsd-signature tsd-kind-icon">on<span class="tsd-signature-symbol">(</span>eventName<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span>, listener<span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> => </span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="_internal_.EventEmitter-1.html" class="tsd-signature-type" data-tsd-kind="Class">EventEmitter</a></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/_internal_.EventEmitter-2.html">EventEmitter</a>.<a href="../interfaces/_internal_.EventEmitter-2.html#on">on</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:330</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Adds the <code>listener</code> function to the end of the listeners array for the
event named <code>eventName</code>. No checks are made to see if the <code>listener</code> has
already been added. Multiple calls passing the same combination of <code>eventName</code>and <code>listener</code> will result in the <code>listener</code> being added, and called, multiple
times.</p>
</div><div><pre><code class="language-js"><span class="hl-2">server</span><span class="hl-0">.</span><span class="hl-7">on</span><span class="hl-0">(</span><span class="hl-3">'connection'</span><span class="hl-0">, (</span><span class="hl-2">stream</span><span class="hl-0">) </span><span class="hl-4">=></span><span class="hl-0"> {</span><br/><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">'someone connected!'</span><span class="hl-0">);</span><br/><span class="hl-0">});</span>
</code></pre>
<p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>
<p>By default, event listeners are invoked in the order they are added. The<code>emitter.prependListener()</code> method can be used as an alternative to add the
event listener to the beginning of the listeners array.</p>
<pre><code class="language-js"><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">myEE</span><span class="hl-0"> = </span><span class="hl-4">new</span><span class="hl-0"> </span><span class="hl-7">EventEmitter</span><span class="hl-0">();</span><br/><span class="hl-2">myEE</span><span class="hl-0">.</span><span class="hl-7">on</span><span class="hl-0">(</span><span class="hl-3">'foo'</span><span class="hl-0">, () </span><span class="hl-4">=></span><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">'a'</span><span class="hl-0">));</span><br/><span class="hl-2">myEE</span><span class="hl-0">.</span><span class="hl-7">prependListener</span><span class="hl-0">(</span><span class="hl-3">'foo'</span><span class="hl-0">, () </span><span class="hl-4">=></span><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">'b'</span><span class="hl-0">));</span><br/><span class="hl-2">myEE</span><span class="hl-0">.</span><span class="hl-7">emit</span><span class="hl-0">(</span><span class="hl-3">'foo'</span><span class="hl-0">);</span><br/><span class="hl-8">// Prints:</span><br/><span class="hl-8">// b</span><br/><span class="hl-8">// a</span>
</code></pre>
</div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v0.1.101</p>
</dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>eventName: <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
<p>The name of the event.</p>
</div></div></li><li><h5>listener: <span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> => </span><span class="tsd-signature-type">void</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
<p>The callback function</p>
</div></div><ul class="tsd-parameters"><li class="tsd-parameter-signature"><ul class="tsd-signatures tsd-kind-type-literal tsd-is-external"><li class="tsd-signature tsd-kind-icon"><span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5><span class="tsd-flag ts-flagRest">Rest</span> <span class="tsd-signature-symbol">...</span>args: <span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4></li></ul></li></ul></li></ul><h4 class="tsd-returns-title">Returns <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="_internal_.EventEmitter-1.html" class="tsd-signature-type" data-tsd-kind="Class">EventEmitter</a></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a id="once" class="tsd-anchor"></a><h3 class="tsd-anchor-link">once<a href="#once" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><li class="tsd-signature tsd-kind-icon">once<span class="tsd-signature-symbol">(</span>eventName<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span>, listener<span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> => </span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="_internal_.EventEmitter-1.html" class="tsd-signature-type" data-tsd-kind="Class">EventEmitter</a></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/_internal_.EventEmitter-2.html">EventEmitter</a>.<a href="../interfaces/_internal_.EventEmitter-2.html#once">once</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:359</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Adds a <strong>one-time</strong><code>listener</code> function for the event named <code>eventName</code>. The
next time <code>eventName</code> is triggered, this listener is removed and then invoked.</p>
</div><div><pre><code class="language-js"><span class="hl-2">server</span><span class="hl-0">.</span><span class="hl-7">once</span><span class="hl-0">(</span><span class="hl-3">'connection'</span><span class="hl-0">, (</span><span class="hl-2">stream</span><span class="hl-0">) </span><span class="hl-4">=></span><span class="hl-0"> {</span><br/><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">'Ah, we have our first user!'</span><span class="hl-0">);</span><br/><span class="hl-0">});</span>
</code></pre>
<p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>
<p>By default, event listeners are invoked in the order they are added. The<code>emitter.prependOnceListener()</code> method can be used as an alternative to add the
event listener to the beginning of the listeners array.</p>
<pre><code class="language-js"><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">myEE</span><span class="hl-0"> = </span><span class="hl-4">new</span><span class="hl-0"> </span><span class="hl-7">EventEmitter</span><span class="hl-0">();</span><br/><span class="hl-2">myEE</span><span class="hl-0">.</span><span class="hl-7">once</span><span class="hl-0">(</span><span class="hl-3">'foo'</span><span class="hl-0">, () </span><span class="hl-4">=></span><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">'a'</span><span class="hl-0">));</span><br/><span class="hl-2">myEE</span><span class="hl-0">.</span><span class="hl-7">prependOnceListener</span><span class="hl-0">(</span><span class="hl-3">'foo'</span><span class="hl-0">, () </span><span class="hl-4">=></span><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">'b'</span><span class="hl-0">));</span><br/><span class="hl-2">myEE</span><span class="hl-0">.</span><span class="hl-7">emit</span><span class="hl-0">(</span><span class="hl-3">'foo'</span><span class="hl-0">);</span><br/><span class="hl-8">// Prints:</span><br/><span class="hl-8">// b</span><br/><span class="hl-8">// a</span>
</code></pre>
</div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v0.3.0</p>
</dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>eventName: <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
<p>The name of the event.</p>
</div></div></li><li><h5>listener: <span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> => </span><span class="tsd-signature-type">void</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
<p>The callback function</p>
</div></div><ul class="tsd-parameters"><li class="tsd-parameter-signature"><ul class="tsd-signatures tsd-kind-type-literal tsd-is-external"><li class="tsd-signature tsd-kind-icon"><span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5><span class="tsd-flag ts-flagRest">Rest</span> <span class="tsd-signature-symbol">...</span>args: <span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4></li></ul></li></ul></li></ul><h4 class="tsd-returns-title">Returns <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="_internal_.EventEmitter-1.html" class="tsd-signature-type" data-tsd-kind="Class">EventEmitter</a></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a id="prependListener" class="tsd-anchor"></a><h3 class="tsd-anchor-link">prepend<wbr/>Listener<a href="#prependListener" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><li class="tsd-signature tsd-kind-icon">prepend<wbr/>Listener<span class="tsd-signature-symbol">(</span>eventName<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span>, listener<span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> => </span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="_internal_.EventEmitter-1.html" class="tsd-signature-type" data-tsd-kind="Class">EventEmitter</a></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/_internal_.EventEmitter-2.html">EventEmitter</a>.<a href="../interfaces/_internal_.EventEmitter-2.html#prependListener">prependListener</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:579</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Adds the <code>listener</code> function to the <em>beginning</em> of the listeners array for the
event named <code>eventName</code>. No checks are made to see if the <code>listener</code> has
already been added. Multiple calls passing the same combination of <code>eventName</code>and <code>listener</code> will result in the <code>listener</code> being added, and called, multiple
times.</p>
</div><div><pre><code class="language-js"><span class="hl-2">server</span><span class="hl-0">.</span><span class="hl-7">prependListener</span><span class="hl-0">(</span><span class="hl-3">'connection'</span><span class="hl-0">, (</span><span class="hl-2">stream</span><span class="hl-0">) </span><span class="hl-4">=></span><span class="hl-0"> {</span><br/><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">'someone connected!'</span><span class="hl-0">);</span><br/><span class="hl-0">});</span>
</code></pre>
<p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>
</div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v6.0.0</p>
</dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>eventName: <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
<p>The name of the event.</p>
</div></div></li><li><h5>listener: <span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> => </span><span class="tsd-signature-type">void</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
<p>The callback function</p>
</div></div><ul class="tsd-parameters"><li class="tsd-parameter-signature"><ul class="tsd-signatures tsd-kind-type-literal tsd-is-external"><li class="tsd-signature tsd-kind-icon"><span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5><span class="tsd-flag ts-flagRest">Rest</span> <span class="tsd-signature-symbol">...</span>args: <span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4></li></ul></li></ul></li></ul><h4 class="tsd-returns-title">Returns <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="_internal_.EventEmitter-1.html" class="tsd-signature-type" data-tsd-kind="Class">EventEmitter</a></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a id="prependOnceListener" class="tsd-anchor"></a><h3 class="tsd-anchor-link">prepend<wbr/>Once<wbr/>Listener<a href="#prependOnceListener" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><li class="tsd-signature tsd-kind-icon">prepend<wbr/>Once<wbr/>Listener<span class="tsd-signature-symbol">(</span>eventName<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span>, listener<span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> => </span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="_internal_.EventEmitter-1.html" class="tsd-signature-type" data-tsd-kind="Class">EventEmitter</a></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/_internal_.EventEmitter-2.html">EventEmitter</a>.<a href="../interfaces/_internal_.EventEmitter-2.html#prependOnceListener">prependOnceListener</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:595</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Adds a <strong>one-time</strong><code>listener</code> function for the event named <code>eventName</code> to the_beginning_ of the listeners array. The next time <code>eventName</code> is triggered, this
listener is removed, and then invoked.</p>
</div><div><pre><code class="language-js"><span class="hl-2">server</span><span class="hl-0">.</span><span class="hl-7">prependOnceListener</span><span class="hl-0">(</span><span class="hl-3">'connection'</span><span class="hl-0">, (</span><span class="hl-2">stream</span><span class="hl-0">) </span><span class="hl-4">=></span><span class="hl-0"> {</span><br/><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">'Ah, we have our first user!'</span><span class="hl-0">);</span><br/><span class="hl-0">});</span>
</code></pre>
<p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>
</div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v6.0.0</p>
</dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>eventName: <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
<p>The name of the event.</p>
</div></div></li><li><h5>listener: <span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> => </span><span class="tsd-signature-type">void</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
<p>The callback function</p>
</div></div><ul class="tsd-parameters"><li class="tsd-parameter-signature"><ul class="tsd-signatures tsd-kind-type-literal tsd-is-external"><li class="tsd-signature tsd-kind-icon"><span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5><span class="tsd-flag ts-flagRest">Rest</span> <span class="tsd-signature-symbol">...</span>args: <span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4></li></ul></li></ul></li></ul><h4 class="tsd-returns-title">Returns <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="_internal_.EventEmitter-1.html" class="tsd-signature-type" data-tsd-kind="Class">EventEmitter</a></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a id="rawListeners" class="tsd-anchor"></a><h3 class="tsd-anchor-link">raw<wbr/>Listeners<a href="#rawListeners" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><li class="tsd-signature tsd-kind-icon">raw<wbr/>Listeners<span class="tsd-signature-symbol">(</span>eventName<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Function</span><span class="tsd-signature-symbol">[]</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/_internal_.EventEmitter-2.html">EventEmitter</a>.<a href="../interfaces/_internal_.EventEmitter-2.html#rawListeners">rawListeners</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:514</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Returns a copy of the array of listeners for the event named <code>eventName</code>,
including any wrappers (such as those created by <code>.once()</code>).</p>
</div><div><pre><code class="language-js"><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">emitter</span><span class="hl-0"> = </span><span class="hl-4">new</span><span class="hl-0"> </span><span class="hl-7">EventEmitter</span><span class="hl-0">();</span><br/><span class="hl-2">emitter</span><span class="hl-0">.</span><span class="hl-7">once</span><span class="hl-0">(</span><span class="hl-3">'log'</span><span class="hl-0">, () </span><span class="hl-4">=></span><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">'log once'</span><span class="hl-0">));</span><br/><br/><span class="hl-8">// Returns a new Array with a function `onceWrapper` which has a property</span><br/><span class="hl-8">// `listener` which contains the original listener bound above</span><br/><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">listeners</span><span class="hl-0"> = </span><span class="hl-2">emitter</span><span class="hl-0">.</span><span class="hl-7">rawListeners</span><span class="hl-0">(</span><span class="hl-3">'log'</span><span class="hl-0">);</span><br/><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">logFnWrapper</span><span class="hl-0"> = </span><span class="hl-2">listeners</span><span class="hl-0">[</span><span class="hl-6">0</span><span class="hl-0">];</span><br/><br/><span class="hl-8">// Logs "log once" to the console and does not unbind the `once` event</span><br/><span class="hl-2">logFnWrapper</span><span class="hl-0">.</span><span class="hl-7">listener</span><span class="hl-0">();</span><br/><br/><span class="hl-8">// Logs "log once" to the console and removes the listener</span><br/><span class="hl-7">logFnWrapper</span><span class="hl-0">();</span><br/><br/><span class="hl-2">emitter</span><span class="hl-0">.</span><span class="hl-7">on</span><span class="hl-0">(</span><span class="hl-3">'log'</span><span class="hl-0">, () </span><span class="hl-4">=></span><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">'log persistently'</span><span class="hl-0">));</span><br/><span class="hl-8">// Will return a new Array with a single function bound by `.on()` above</span><br/><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">newListeners</span><span class="hl-0"> = </span><span class="hl-2">emitter</span><span class="hl-0">.</span><span class="hl-7">rawListeners</span><span class="hl-0">(</span><span class="hl-3">'log'</span><span class="hl-0">);</span><br/><br/><span class="hl-8">// Logs "log persistently" twice</span><br/><span class="hl-2">newListeners</span><span class="hl-0">[</span><span class="hl-6">0</span><span class="hl-0">]();</span><br/><span class="hl-2">emitter</span><span class="hl-0">.</span><span class="hl-7">emit</span><span class="hl-0">(</span><span class="hl-3">'log'</span><span class="hl-0">);</span>
</code></pre>
</div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v9.4.0</p>
</dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>eventName: <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Function</span><span class="tsd-signature-symbol">[]</span></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a id="removeAllListeners" class="tsd-anchor"></a><h3 class="tsd-anchor-link">remove<wbr/>All<wbr/>Listeners<a href="#removeAllListeners" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><li class="tsd-signature tsd-kind-icon">remove<wbr/>All<wbr/>Listeners<span class="tsd-signature-symbol">(</span>event<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="_internal_.EventEmitter-1.html" class="tsd-signature-type" data-tsd-kind="Class">EventEmitter</a></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/_internal_.EventEmitter-2.html">EventEmitter</a>.<a href="../interfaces/_internal_.EventEmitter-2.html#removeAllListeners">removeAllListeners</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:455</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Removes all listeners, or those of the specified <code>eventName</code>.</p>
</div><div><p>It is bad practice to remove listeners added elsewhere in the code,
particularly when the <code>EventEmitter</code> instance was created by some other
component or module (e.g. sockets or file streams).</p>
<p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>
</div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v0.1.26</p>
</dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5><span class="tsd-flag ts-flagOptional">Optional</span> event: <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span></h5></li></ul><h4 class="tsd-returns-title">Returns <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="_internal_.EventEmitter-1.html" class="tsd-signature-type" data-tsd-kind="Class">EventEmitter</a></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a id="removeListener" class="tsd-anchor"></a><h3 class="tsd-anchor-link">remove<wbr/>Listener<a href="#removeListener" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><li class="tsd-signature tsd-kind-icon">remove<wbr/>Listener<span class="tsd-signature-symbol">(</span>eventName<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span>, listener<span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> => </span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="_internal_.EventEmitter-1.html" class="tsd-signature-type" data-tsd-kind="Class">EventEmitter</a></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/_internal_.EventEmitter-2.html">EventEmitter</a>.<a href="../interfaces/_internal_.EventEmitter-2.html#removeListener">removeListener</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:439</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Removes the specified <code>listener</code> from the listener array for the event named<code>eventName</code>.</p>
</div><div><pre><code class="language-js"><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-7">callback</span><span class="hl-0"> = (</span><span class="hl-2">stream</span><span class="hl-0">) </span><span class="hl-4">=></span><span class="hl-0"> {</span><br/><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">'someone connected!'</span><span class="hl-0">);</span><br/><span class="hl-0">};</span><br/><span class="hl-2">server</span><span class="hl-0">.</span><span class="hl-7">on</span><span class="hl-0">(</span><span class="hl-3">'connection'</span><span class="hl-0">, </span><span class="hl-2">callback</span><span class="hl-0">);</span><br/><span class="hl-8">// ...</span><br/><span class="hl-2">server</span><span class="hl-0">.</span><span class="hl-7">removeListener</span><span class="hl-0">(</span><span class="hl-3">'connection'</span><span class="hl-0">, </span><span class="hl-2">callback</span><span class="hl-0">);</span>
</code></pre>
<p><code>removeListener()</code> will remove, at most, one instance of a listener from the
listener array. If any single listener has been added multiple times to the
listener array for the specified <code>eventName</code>, then <code>removeListener()</code> must be
called multiple times to remove each instance.</p>
<p>Once an event is emitted, all listeners attached to it at the
time of emitting are called in order. This implies that any<code>removeListener()</code> or <code>removeAllListeners()</code> calls <em>after</em> emitting and_before_ the last listener finishes execution will
not remove them from<code>emit()</code> in progress. Subsequent events behave as expected.</p>
<pre><code class="language-js"><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">myEmitter</span><span class="hl-0"> = </span><span class="hl-4">new</span><span class="hl-0"> </span><span class="hl-7">MyEmitter</span><span class="hl-0">();</span><br/><br/><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-7">callbackA</span><span class="hl-0"> = () </span><span class="hl-4">=></span><span class="hl-0"> {</span><br/><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">'A'</span><span class="hl-0">);</span><br/><span class="hl-0"> </span><span class="hl-2">myEmitter</span><span class="hl-0">.</span><span class="hl-7">removeListener</span><span class="hl-0">(</span><span class="hl-3">'event'</span><span class="hl-0">, </span><span class="hl-2">callbackB</span><span class="hl-0">);</span><br/><span class="hl-0">};</span><br/><br/><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-7">callbackB</span><span class="hl-0"> = () </span><span class="hl-4">=></span><span class="hl-0"> {</span><br/><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">'B'</span><span class="hl-0">);</span><br/><span class="hl-0">};</span><br/><br/><span class="hl-2">myEmitter</span><span class="hl-0">.</span><span class="hl-7">on</span><span class="hl-0">(</span><span class="hl-3">'event'</span><span class="hl-0">, </span><span class="hl-2">callbackA</span><span class="hl-0">);</span><br/><br/><span class="hl-2">myEmitter</span><span class="hl-0">.</span><span class="hl-7">on</span><span class="hl-0">(</span><span class="hl-3">'event'</span><span class="hl-0">, </span><span class="hl-2">callbackB</span><span class="hl-0">);</span><br/><br/><span class="hl-8">// callbackA removes listener callbackB but it will still be called.</span><br/><span class="hl-8">// Internal listener array at time of emit [callbackA, callbackB]</span><br/><span class="hl-2">myEmitter</span><span class="hl-0">.</span><span class="hl-7">emit</span><span class="hl-0">(</span><span class="hl-3">'event'</span><span class="hl-0">);</span><br/><span class="hl-8">// Prints:</span><br/><span class="hl-8">// A</span><br/><span class="hl-8">// B</span><br/><br/><span class="hl-8">// callbackB is now removed.</span><br/><span class="hl-8">// Internal listener array [callbackA]</span><br/><span class="hl-2">myEmitter</span><span class="hl-0">.</span><span class="hl-7">emit</span><span class="hl-0">(</span><span class="hl-3">'event'</span><span class="hl-0">);</span><br/><span class="hl-8">// Prints:</span><br/><span class="hl-8">// A</span>
</code></pre>
<p>Because listeners are managed using an internal array, calling this will
change the position indices of any listener registered <em>after</em> the listener
being removed. This will not impact the order in which listeners are called,
but it means that any copies of the listener array as returned by
the <code>emitter.listeners()</code> method will need to be recreated.</p>
<p>When a single function has been added as a handler multiple times for a single
event (as in the example below), <code>removeListener()</code> will remove the most
recently added instance. In the example the <code>once('ping')</code>listener is removed:</p>
<pre><code class="language-js"><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">ee</span><span class="hl-0"> = </span><span class="hl-4">new</span><span class="hl-0"> </span><span class="hl-7">EventEmitter</span><span class="hl-0">();</span><br/><br/><span class="hl-4">function</span><span class="hl-0"> </span><span class="hl-7">pong</span><span class="hl-0">() {</span><br/><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">'pong'</span><span class="hl-0">);</span><br/><span class="hl-0">}</span><br/><br/><span class="hl-2">ee</span><span class="hl-0">.</span><span class="hl-7">on</span><span class="hl-0">(</span><span class="hl-3">'ping'</span><span class="hl-0">, </span><span class="hl-2">pong</span><span class="hl-0">);</span><br/><span class="hl-2">ee</span><span class="hl-0">.</span><span class="hl-7">once</span><span class="hl-0">(</span><span class="hl-3">'ping'</span><span class="hl-0">, </span><span class="hl-2">pong</span><span class="hl-0">);</span><br/><span class="hl-2">ee</span><span class="hl-0">.</span><span class="hl-7">removeListener</span><span class="hl-0">(</span><span class="hl-3">'ping'</span><span class="hl-0">, </span><span class="hl-2">pong</span><span class="hl-0">);</span><br/><br/><span class="hl-2">ee</span><span class="hl-0">.</span><span class="hl-7">emit</span><span class="hl-0">(</span><span class="hl-3">'ping'</span><span class="hl-0">);</span><br/><span class="hl-2">ee</span><span class="hl-0">.</span><span class="hl-7">emit</span><span class="hl-0">(</span><span class="hl-3">'ping'</span><span class="hl-0">);</span>
</code></pre>
<p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>
</div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v0.1.26</p>
</dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>eventName: <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span></h5></li><li><h5>listener: <span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> => </span><span class="tsd-signature-type">void</span></h5><ul class="tsd-parameters"><li class="tsd-parameter-signature"><ul class="tsd-signatures tsd-kind-type-literal tsd-is-external"><li class="tsd-signature tsd-kind-icon"><span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5><span class="tsd-flag ts-flagRest">Rest</span> <span class="tsd-signature-symbol">...</span>args: <span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4></li></ul></li></ul></li></ul><h4 class="tsd-returns-title">Returns <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="_internal_.EventEmitter-1.html" class="tsd-signature-type" data-tsd-kind="Class">EventEmitter</a></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a id="setMaxListeners" class="tsd-anchor"></a><h3 class="tsd-anchor-link">set<wbr/>Max<wbr/>Listeners<a href="#setMaxListeners" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><li class="tsd-signature tsd-kind-icon">set<wbr/>Max<wbr/>Listeners<span class="tsd-signature-symbol">(</span>n<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="_internal_.EventEmitter-1.html" class="tsd-signature-type" data-tsd-kind="Class">EventEmitter</a></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/_internal_.EventEmitter-2.html">EventEmitter</a>.<a href="../interfaces/_internal_.EventEmitter-2.html#setMaxListeners">setMaxListeners</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:465</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>By default <code>EventEmitter</code>s will print a warning if more than <code>10</code> listeners are
added for a particular event. This is a useful default that helps finding
memory leaks. The <code>emitter.setMaxListeners()</code> method allows the limit to be
modified for this specific <code>EventEmitter</code> instance. The value can be set to<code>Infinity</code> (or <code>0</code>) to indicate an unlimited number of listeners.</p>
</div><div><p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>
</div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v0.3.5</p>
</dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>n: <span class="tsd-signature-type">number</span></h5></li></ul><h4 class="tsd-returns-title">Returns <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="_internal_.EventEmitter-1.html" class="tsd-signature-type" data-tsd-kind="Class">EventEmitter</a></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-static tsd-is-external"><a id="getEventListeners" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span class="tsd-flag ts-flagStatic">Static</span> get<wbr/>Event<wbr/>Listeners<a href="#getEventListeners" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-static tsd-is-external"><li class="tsd-signature tsd-kind-icon">get<wbr/>Event<wbr/>Listeners<span class="tsd-signature-symbol">(</span>emitter<span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="../interfaces/_internal_.EventEmitter-2.html" class="tsd-signature-type" data-tsd-kind="Interface">EventEmitter</a><span class="tsd-signature-symbol"> | </span><a href="../interfaces/_internal_.DOMEventTarget.html" class="tsd-signature-type" data-tsd-kind="Interface">DOMEventTarget</a>, name<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Function</span><span class="tsd-signature-symbol">[]</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/events.d.ts:262</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Returns a copy of the array of listeners for the event named <code>eventName</code>.</p>
</div><div><p>For <code>EventEmitter</code>s this behaves exactly the same as calling <code>.listeners</code> on
the emitter.</p>
<p>For <code>EventTarget</code>s this is the only way to get the event listeners for the
event target. This is useful for debugging and diagnostic purposes.</p>
<pre><code class="language-js"><span class="hl-4">const</span><span class="hl-0"> { </span><span class="hl-5">getEventListeners</span><span class="hl-0">, </span><span class="hl-5">EventEmitter</span><span class="hl-0"> } = </span><span class="hl-7">require</span><span class="hl-0">(</span><span class="hl-3">'events'</span><span class="hl-0">);</span><br/><br/><span class="hl-0">{</span><br/><span class="hl-0"> </span><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">ee</span><span class="hl-0"> = </span><span class="hl-4">new</span><span class="hl-0"> </span><span class="hl-7">EventEmitter</span><span class="hl-0">();</span><br/><span class="hl-0"> </span><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-7">listener</span><span class="hl-0"> = () </span><span class="hl-4">=></span><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">'Events are fun'</span><span class="hl-0">);</span><br/><span class="hl-0"> </span><span class="hl-2">ee</span><span class="hl-0">.</span><span class="hl-7">on</span><span class="hl-0">(</span><span class="hl-3">'foo'</span><span class="hl-0">, </span><span class="hl-2">listener</span><span class="hl-0">);</span><br/><span class="hl-0"> </span><span class="hl-7">getEventListeners</span><span class="hl-0">(</span><span class="hl-2">ee</span><span class="hl-0">, </span><span class="hl-3">'foo'</span><span class="hl-0">); </span><span class="hl-8">// [listener]</span><br/><span class="hl-0">}</span><br/><span class="hl-0">{</span><br/><span class="hl-0"> </span><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">et</span><span class="hl-0"> = </span><span class="hl-4">new</span><span class="hl-0"> </span><span class="hl-7">EventTarget</span><span class="hl-0">();</span><br/><span class="hl-0"> </span><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-7">listener</span><span class="hl-0"> = () </span><span class="hl-4">=></span><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">'Events are fun'</span><span class="hl-0">);</span><br/><span class="hl-0"> </span><span class="hl-2">et</span><span class="hl-0">.</span><span class="hl-7">addEventListener</span><span class="hl-0">(</span><span class="hl-3">'foo'</span><span class="hl-0">, </span><span class="hl-2">listener</span><span class="hl-0">);</span><br/><span class="hl-0"> </span><span class="hl-7">getEventListeners</span><span class="hl-0">(</span><span class="hl-2">et</span><span class="hl-0">, </span><span class="hl-3">'foo'</span><span class="hl-0">); </span><span class="hl-8">// [listener]</span><br/><span class="hl-0">}</span>
</code></pre>
</div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v15.2.0, v14.17.0</p>
</dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>emitter: <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="../interfaces/_internal_.EventEmitter-2.html" class="tsd-signature-type" data-tsd-kind="Interface">EventEmitter</a><span class="tsd-signature-symbol"> | </span><a href="../interfaces/_internal_.DOMEventTarget.html" class="tsd-signature-type" data-tsd-kind="Interface">DOMEventTarget</a></h5></li><li><h5>name: <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Function</span><span class="tsd-signature-symbol">[]</span></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external"><a id="listenerCount-1" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span class="tsd-flag ts-flagStatic">Static</span> listener<wbr/>Count<a href="#listenerCount-1" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external"><li class="tsd-signature tsd-kind-icon">listener<wbr/>Count<span class="tsd-signature-symbol">(</span>emitter<span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="../interfaces/_internal_.EventEmitter-2.html" class="tsd-signature-type" data-tsd-kind="Interface">EventEmitter</a>, eventName<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><p>Inherited from NodeJS.EventEmitter.listenerCount</p><ul><li>Defined in node_modules/@types/node/events.d.ts:234</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>A class method that returns the number of listeners for the given <code>eventName</code>registered on the given <code>emitter</code>.</p>
</div><div><pre><code class="language-js"><span class="hl-4">const</span><span class="hl-0"> { </span><span class="hl-5">EventEmitter</span><span class="hl-0">, </span><span class="hl-5">listenerCount</span><span class="hl-0"> } = </span><span class="hl-7">require</span><span class="hl-0">(</span><span class="hl-3">'events'</span><span class="hl-0">);</span><br/><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">myEmitter</span><span class="hl-0"> = </span><span class="hl-4">new</span><span class="hl-0"> </span><span class="hl-7">EventEmitter</span><span class="hl-0">();</span><br/><span class="hl-2">myEmitter</span><span class="hl-0">.</span><span class="hl-7">on</span><span class="hl-0">(</span><span class="hl-3">'event'</span><span class="hl-0">, () </span><span class="hl-4">=></span><span class="hl-0"> {});</span><br/><span class="hl-2">myEmitter</span><span class="hl-0">.</span><span class="hl-7">on</span><span class="hl-0">(</span><span class="hl-3">'event'</span><span class="hl-0">, () </span><span class="hl-4">=></span><span class="hl-0"> {});</span><br/><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-7">listenerCount</span><span class="hl-0">(</span><span class="hl-2">myEmitter</span><span class="hl-0">, </span><span class="hl-3">'event'</span><span class="hl-0">));</span><br/><span class="hl-8">// Prints: 2</span>
</code></pre>
</div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v0.9.12</p>
</dd><dt>deprecated</dt><dd><p>Since v3.2.0 - Use <code>listenerCount</code> instead.</p>
</dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>emitter: <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="../interfaces/_internal_.EventEmitter-2.html" class="tsd-signature-type" data-tsd-kind="Interface">EventEmitter</a></h5><div class="tsd-comment tsd-typography"><div class="lead">
<p>The emitter to query</p>
</div></div></li><li><h5>eventName: <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
<p>The event name</p>
</div></div></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">number</span></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external"><a id="on-1" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span class="tsd-flag ts-flagStatic">Static</span> on<a href="#on-1" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external"><li class="tsd-signature tsd-kind-icon">on<span class="tsd-signature-symbol">(</span>emitter<span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="../interfaces/_internal_.EventEmitter-2.html" class="tsd-signature-type" data-tsd-kind="Interface">EventEmitter</a>, eventName<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, options<span class="tsd-signature-symbol">?: </span><a href="../interfaces/_internal_.StaticEventEmitterOptions.html" class="tsd-signature-type" data-tsd-kind="Interface">StaticEventEmitterOptions</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../interfaces/_internal_.AsyncIterableIterator.html" class="tsd-signature-type" data-tsd-kind="Interface">AsyncIterableIterator</a><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">></span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><p>Inherited from NodeJS.EventEmitter.on</p><ul><li>Defined in node_modules/@types/node/events.d.ts:217</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>```js
const { on, EventEmitter } = require('events');</p>
</div><div><p>(async () => {
const ee = new EventEmitter();</p>
<p> // Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});</p>
<p> for await (const event of on(ee, 'foo')) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
})();</p>
<pre><code><br/><span class="hl-2">Returns</span><span class="hl-0"> </span><span class="hl-2">an</span><span class="hl-0"> </span><span class="hl-3">`AsyncIterator`</span><span class="hl-0"> </span><span class="hl-2">that</span><span class="hl-0"> </span><span class="hl-2">iterates</span><span class="hl-0"> </span><span class="hl-3">`eventName`</span><span class="hl-0"> </span><span class="hl-2">events</span><span class="hl-0">. </span><span class="hl-2">It</span><span class="hl-0"> </span><span class="hl-2">will</span><span class="hl-0"> </span><span class="hl-1">throw</span><br/><span class="hl-1">if</span><span class="hl-0"> </span><span class="hl-2">the</span><span class="hl-0"> </span><span class="hl-3">`EventEmitter`</span><span class="hl-0"> </span><span class="hl-2">emits</span><span class="hl-0"> </span><span class="hl-3">`'error'`</span><span class="hl-0">. </span><span class="hl-2">It</span><span class="hl-0"> </span><span class="hl-2">removes</span><span class="hl-0"> </span><span class="hl-2">all</span><span class="hl-0"> </span><span class="hl-2">listeners</span><span class="hl-0"> </span><span class="hl-2">when</span><br/><span class="hl-2">exiting</span><span class="hl-0"> </span><span class="hl-2">the</span><span class="hl-0"> </span><span class="hl-2">loop</span><span class="hl-0">. </span><span class="hl-2">The</span><span class="hl-0"> </span><span class="hl-3">`value`</span><span class="hl-0"> </span><span class="hl-2">returned</span><span class="hl-0"> </span><span class="hl-2">by</span><span class="hl-0"> </span><span class="hl-2">each</span><span class="hl-0"> </span><span class="hl-2">iteration</span><span class="hl-0"> </span><span class="hl-2">is</span><span class="hl-0"> </span><span class="hl-2">an</span><span class="hl-0"> </span><span class="hl-2">array</span><br/><span class="hl-2">composed</span><span class="hl-0"> </span><span class="hl-4">of</span><span class="hl-0"> </span><span class="hl-2">the</span><span class="hl-0"> </span><span class="hl-2">emitted</span><span class="hl-0"> </span><span class="hl-2">event</span><span class="hl-0"> </span><span class="hl-4">arguments</span><span class="hl-0">.</span><br/><br/><span class="hl-2">An</span><span class="hl-0"> </span><span class="hl-3">`AbortSignal`</span><span class="hl-0"> </span><span class="hl-2">can</span><span class="hl-0"> </span><span class="hl-2">be</span><span class="hl-0"> </span><span class="hl-2">used</span><span class="hl-0"> </span><span class="hl-2">to</span><span class="hl-0"> </span><span class="hl-2">cancel</span><span class="hl-0"> </span><span class="hl-2">waiting</span><span class="hl-0"> </span><span class="hl-2">on</span><span class="hl-0"> </span><span class="hl-10">events</span><span class="hl-0">:</span><br/><br/><span class="hl-3">```js</span><br/><span class="hl-3">const { on, EventEmitter } = require('events');</span><br/><span class="hl-3">const ac = new AbortController();</span><br/><br/><span class="hl-3">(async () => {</span><br/><span class="hl-3"> const ee = new EventEmitter();</span><br/><br/><span class="hl-3"> // Emit later on</span><br/><span class="hl-3"> process.nextTick(() => {</span><br/><span class="hl-3"> ee.emit('foo', 'bar');</span><br/><span class="hl-3"> ee.emit('foo', 42);</span><br/><span class="hl-3"> });</span><br/><br/><span class="hl-3"> for await (const event of on(ee, 'foo', { signal: ac.signal })) {</span><br/><span class="hl-3"> // The execution of this inner block is synchronous and it</span><br/><span class="hl-3"> // processes one event at a time (even with await). Do not use</span><br/><span class="hl-3"> // if concurrent execution is required.</span><br/><span class="hl-3"> console.log(event); // prints ['bar'] [42]</span><br/><span class="hl-3"> }</span><br/><span class="hl-3"> // Unreachable here</span><br/><span class="hl-3">})();</span><br/><br/><span class="hl-3">process.nextTick(() => ac.abort());</span>
</code></pre>
</div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v13.6.0, v12.16.0</p>
</dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>emitter: <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace"><internal></a><span class="tsd-signature-symbol">.</span><a href="../interfaces/_internal_.EventEmitter-2.html" class="tsd-signature-type" data-tsd-kind="Interface">EventEmitter</a></h5></li><li><h5>eventName: <span class="tsd-signature-type">string</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
<p>The name of the event being listened for</p>
</div></div></li><li><h5><span class="tsd-flag ts-flagOptional">Optional</span> options: <a href="../interfaces/_internal_.StaticEventEmitterOptions.html" class="tsd-signature-type" data-tsd-kind="Interface">StaticEventEmitterOptions</a></h5></li></ul><h4 class="tsd-returns-title">Returns <a href="../interfaces/_internal_.AsyncIterableIterator.html" class="tsd-signature-type" data-tsd-kind="Interface">AsyncIterableIterator</a><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">></span></h4><div><p>that iterates <code>eventName</code> events emitted by the <code>emitter</code></p>
</div></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external"><a id="once-1" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span class="tsd-flag ts-flagStatic">Static</span> once<a href="#once-1" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external"><li class="tsd-signature tsd-kind-icon">once<span class="tsd-signature-symbol">(</span>emitter<span class="tsd-signature-symbol">: </span><a href="../interfaces/_internal_.NodeEventTarget.html" class="tsd-signature-type" data-tsd-kind="Interface">NodeEventTarget</a>, eventName<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span>, options<span class="tsd-signature-symbol">?: </span><a href="../interfaces/_internal_.StaticEventEmitterOptions.html" class="tsd-signature-type" data-tsd-kind="Interface">StaticEventEmitterOptions</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">></span></li><li class="tsd-signature tsd-kind-icon">once<span class="tsd-signature-symbol">(</span>emitter<span class="tsd-signature-symbol">: </span><a href="../interfaces/_internal_.DOMEventTarget.html" class="tsd-signature-type" data-tsd-kind="Interface">DOMEventTarget</a>, eventName<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, options<span class="tsd-signature-symbol">?: </span><a href="../interfaces/_internal_.StaticEventEmitterOptions.html" class="tsd-signature-type" data-tsd-kind="Interface">StaticEventEmitterOptions</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">></span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><p>Inherited from NodeJS.EventEmitter.once</p><ul><li>Defined in node_modules/@types/node/events.d.ts:157</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Creates a <code>Promise</code> that is fulfilled when the <code>EventEmitter</code> emits the given
event or that is rejected if the <code>EventEmitter</code> emits <code>'error'</code> while waiting.
The <code>Promise</code> will resolve with an array of all the arguments emitted to the
given event.</p>
</div><div><p>This method is intentionally generic and works with the web platform <a href="https://dom.spec.whatwg.org/#interface-eventtarget">EventTarget</a> interface, which has no special<code>'error'</code> event
semantics and does not listen to the <code>'error'</code> event.</p>
<pre><code class="language-js"><span class="hl-4">const</span><span class="hl-0"> { </span><span class="hl-5">once</span><span class="hl-0">, </span><span class="hl-5">EventEmitter</span><span class="hl-0"> } = </span><span class="hl-7">require</span><span class="hl-0">(</span><span class="hl-3">'events'</span><span class="hl-0">);</span><br/><br/><span class="hl-4">async</span><span class="hl-0"> </span><span class="hl-4">function</span><span class="hl-0"> </span><span class="hl-7">run</span><span class="hl-0">() {</span><br/><span class="hl-0"> </span><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">ee</span><span class="hl-0"> = </span><span class="hl-4">new</span><span class="hl-0"> </span><span class="hl-7">EventEmitter</span><span class="hl-0">();</span><br/><br/><span class="hl-0"> </span><span class="hl-2">process</span><span class="hl-0">.</span><span class="hl-7">nextTick</span><span class="hl-0">(() </span><span class="hl-4">=></span><span class="hl-0"> {</span><br/><span class="hl-0"> </span><span class="hl-2">ee</span><span class="hl-0">.</span><span class="hl-7">emit</span><span class="hl-0">(</span><span class="hl-3">'myevent'</span><span class="hl-0">, </span><span class="hl-6">42</span><span class="hl-0">);</span><br/><span class="hl-0"> });</span><br/><br/><span class="hl-0"> </span><span class="hl-4">const</span><span class="hl-0"> [</span><span class="hl-5">value</span><span class="hl-0">] = </span><span class="hl-1">await</span><span class="hl-0"> </span><span class="hl-7">once</span><span class="hl-0">(</span><span class="hl-2">ee</span><span class="hl-0">, </span><span class="hl-3">'myevent'</span><span class="hl-0">);</span><br/><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-2">value</span><span class="hl-0">);</span><br/><br/><span class="hl-0"> </span><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">err</span><span class="hl-0"> = </span><span class="hl-4">new</span><span class="hl-0"> </span><span class="hl-9">Error</span><span class="hl-0">(</span><span class="hl-3">'kaboom'</span><span class="hl-0">);</span><br/><span class="hl-0"> </span><span class="hl-2">process</span><span class="hl-0">.</span><span class="hl-7">nextTick</span><span class="hl-0">(() </span><span class="hl-4">=></span><span class="hl-0"> {</span><br/><span class="hl-0"> </span><span class="hl-2">ee</span><span class="hl-0">.</span><span class="hl-7">emit</span><span class="hl-0">(</span><span class="hl-3">'error'</span><span class="hl-0">, </span><span class="hl-2">err</span><span class="hl-0">);</span><br/><span class="hl-0"> });</span><br/><br/><span class="hl-0"> </span><span class="hl-1">try</span><span class="hl-0"> {</span><br/><span class="hl-0"> </span><span class="hl-1">await</span><span class="hl-0"> </span><span class="hl-7">once</span><span class="hl-0">(</span><span class="hl-2">ee</span><span class="hl-0">, </span><span class="hl-3">'myevent'</span><span class="hl-0">);</span><br/><span class="hl-0"> } </span><span class="hl-1">catch</span><span class="hl-0"> (</span><span class="hl-2">err</span><span class="hl-0">) {</span><br/><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">'error happened'</span><span class="hl-0">, </span><span class="hl-2">err</span><span class="hl-0">);</span><br/><span class="hl-0"> }</span><br/><span class="hl-0">}</span><br/><br/><span class="hl-7">run</span><span class="hl-0">();</span>
</code></pre>
<p>The special handling of the <code>'error'</code> event is only used when <code>events.once()</code>is used to wait for another event. If <code>events.once()</code> is used to wait for the
'<code>error'</code> event itself, then it is treated as any other kind of event without
special handling:</p>
<pre><code class="language-js"><span class="hl-4">const</span><span class="hl-0"> { </span><span class="hl-5">EventEmitter</span><span class="hl-0">, </span><span class="hl-5">once</span><span class="hl-0"> } = </span><span class="hl-7">require</span><span class="hl-0">(</span><span class="hl-3">'events'</span><span class="hl-0">);</span><br/><br/><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">ee</span><span class="hl-0"> = </span><span class="hl-4">new</span><span class="hl-0"> </span><span class="hl-7">EventEmitter</span><span class="hl-0">();</span><br/><br/><span class="hl-7">once</span><span class="hl-0">(</span><span class="hl-2">ee</span><span class="hl-0">, </span><span class="hl-3">'error'</span><span class="hl-0">)</span><br/><span class="hl-0"> .</span><span class="hl-7">then</span><span class="hl-0">(([</span><span class="hl-2">err</span><span class="hl-0">]) </span><span class="hl-4">=></span><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">'ok'</span><span class="hl-0">, </span><span class="hl-2">err</span><span class="hl-0">.</span><span class="hl-2">message</span><span class="hl-0">))</span><br/><span class="hl-0"> .</span><span class="hl-7">catch</span><span class="hl-0">((</span><span class="hl-2">err</span><span class="hl-0">) </span><span class="hl-4">=></span><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">'error'</span><span class="hl-0">, </span><span class="hl-2">err</span><span class="hl-0">.</span><span class="hl-2">message</span><span class="hl-0">));</span><br/><br/><span class="hl-2">ee</span><span class="hl-0">.</span><span class="hl-7">emit</span><span class="hl-0">(</span><span class="hl-3">'error'</span><span class="hl-0">, </span><span class="hl-4">new</span><span class="hl-0"> </span><span class="hl-9">Error</span><span class="hl-0">(</span><span class="hl-3">'boom'</span><span class="hl-0">));</span><br/><br/><span class="hl-8">// Prints: ok boom</span>
</code></pre>
<p>An <code>AbortSignal</code> can be used to cancel waiting for the event:</p>
<pre><code class="language-js"><span class="hl-4">const</span><span class="hl-0"> { </span><span class="hl-5">EventEmitter</span><span class="hl-0">, </span><span class="hl-5">once</span><span class="hl-0"> } = </span><span class="hl-7">require</span><span class="hl-0">(</span><span class="hl-3">'events'</span><span class="hl-0">);</span><br/><br/><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">ee</span><span class="hl-0"> = </span><span class="hl-4">new</span><span class="hl-0"> </span><span class="hl-7">EventEmitter</span><span class="hl-0">();</span><br/><span class="hl-4">const</span><span class="hl-0"> </span><span class="hl-5">ac</span><span class="hl-0"> = </span><span class="hl-4">new</span><span class="hl-0"> </span><span class="hl-7">AbortController</span><span class="hl-0">();</span><br/><br/><span class="hl-4">async</span><span class="hl-0"> </span><span class="hl-4">function</span><span class="hl-0"> </span><span class="hl-7">foo</span><span class="hl-0">(</span><span class="hl-2">emitter</span><span class="hl-0">, </span><span class="hl-2">event</span><span class="hl-0">, </span><span class="hl-2">signal</span><span class="hl-0">) {</span><br/><span class="hl-0"> </span><span class="hl-1">try</span><span class="hl-0"> {</span><br/><span class="hl-0"> </span><span class="hl-1">await</span><span class="hl-0"> </span><span class="hl-7">once</span><span class="hl-0">(</span><span class="hl-2">emitter</span><span class="hl-0">, </span><span class="hl-2">event</span><span class="hl-0">, { </span><span class="hl-2">signal</span><span class="hl-0"> });</span><br/><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">log</span><span class="hl-0">(</span><span class="hl-3">'event emitted!'</span><span class="hl-0">);</span><br/><span class="hl-0"> } </span><span class="hl-1">catch</span><span class="hl-0"> (</span><span class="hl-2">error</span><span class="hl-0">) {</span><br/><span class="hl-0"> </span><span class="hl-1">if</span><span class="hl-0"> (</span><span class="hl-2">error</span><span class="hl-0">.</span><span class="hl-2">name</span><span class="hl-0"> === </span><span class="hl-3">'AbortError'</span><span class="hl-0">) {</span><br/><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">error</span><span class="hl-0">(</span><span class="hl-3">'Waiting for the event was canceled!'</span><span class="hl-0">);</span><br/><span class="hl-0"> } </span><span class="hl-1">else</span><span class="hl-0"> {</span><br/><span class="hl-0"> </span><span class="hl-2">console</span><span class="hl-0">.</span><span class="hl-7">error</span><span class="hl-0">(</span><span class="hl-3">'There was an error'</span><span class="hl-0">, </span><span class="hl-2">error</span><span class="hl-0">.</span><span class="hl-2">message</span><span class="hl-0">);</span><br/><span class="hl-0"> }</span><br/><span class="hl-0"> }</span><br/><span class="hl-0">}</span><br/><br/><span class="hl-7">foo</span><span class="hl-0">(</span><span class="hl-2">ee</span><span class="hl-0">, </span><span class="hl-3">'foo'</span><span class="hl-0">, </span><span class="hl-2">ac</span><span class="hl-0">.</span><span class="hl-2">signal</span><span class="hl-0">);</span><br/><span class="hl-2">ac</span><span class="hl-0">.</span><span class="hl-7">abort</span><span class="hl-0">(); </span><span class="hl-8">// Abort waiting for the event</span><br/><span class="hl-2">ee</span><span class="hl-0">.</span><span class="hl-7">emit</span><span class="hl-0">(</span><span class="hl-3">'foo'</span><span class="hl-0">); </span><span class="hl-8">// Prints: Waiting for the event was canceled!</span>
</code></pre>
</div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v11.13.0, v10.16.0</p>
</dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>emitter: <a href="../interfaces/_internal_.NodeEventTarget.html" class="tsd-signature-type" data-tsd-kind="Interface">NodeEventTarget</a></h5></li><li><h5>eventName: <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">symbol</span></h5></li><li><h5><span class="tsd-flag ts-flagOptional">Optional</span> options: <a href="../interfaces/_internal_.StaticEventEmitterOptions.html" class="tsd-signature-type" data-tsd-kind="Interface">StaticEventEmitterOptions</a></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">></span></h4></li><li class="tsd-description"><aside class="tsd-sources"><p>Inherited from NodeJS.EventEmitter.once</p><ul><li>Defined in node_modules/@types/node/events.d.ts:158</li></ul></aside><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>emitter: <a href="../interfaces/_internal_.DOMEventTarget.html" class="tsd-signature-type" data-tsd-kind="Interface">DOMEventTarget</a></h5></li><li><h5>eventName: <span class="tsd-signature-type">string</span></h5></li><li><h5><span class="tsd-flag ts-flagOptional">Optional</span> options: <a href="../interfaces/_internal_.StaticEventEmitterOptions.html" class="tsd-signature-type" data-tsd-kind="Interface">StaticEventEmitterOptions</a></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">></span></h4></li></ul></section></section></div><div class="col-4 col-menu menu-sticky-wrap menu-highlight"><nav class="tsd-navigation primary"><ul><li class=""><a href="../modules.html">Exports</a></li><li class="current tsd-kind-namespace"><a href="../modules/_internal_.html"><internal></a><ul><li class=" tsd-kind-namespace tsd-parent-kind-namespace tsd-is-external"><a href="../modules/_internal_.EventEmitter.html">Event<wbr/>Emitter</a></li></ul></li></ul></nav><nav class="tsd-navigation secondary menu-sticky"><ul><li class="current tsd-kind-class tsd-parent-kind-namespace tsd-is-external"><a href="_internal_.EventEmitter-1.html" class="tsd-kind-icon">Event<wbr/>Emitter</a><ul><li class="tsd-kind-constructor tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#constructor" class="tsd-kind-icon">constructor</a></li><li class="tsd-kind-property tsd-parent-kind-class tsd-is-static tsd-is-external"><a href="_internal_.EventEmitter-1.html#captureRejectionSymbol" class="tsd-kind-icon">capture<wbr/>Rejection<wbr/>Symbol</a></li><li class="tsd-kind-property tsd-parent-kind-class tsd-is-static tsd-is-external"><a href="_internal_.EventEmitter-1.html#captureRejections" class="tsd-kind-icon">capture<wbr/>Rejections</a></li><li class="tsd-kind-property tsd-parent-kind-class tsd-is-static tsd-is-external"><a href="_internal_.EventEmitter-1.html#defaultMaxListeners" class="tsd-kind-icon">default<wbr/>Max<wbr/>Listeners</a></li><li class="tsd-kind-property tsd-parent-kind-class tsd-is-static tsd-is-external"><a href="_internal_.EventEmitter-1.html#errorMonitor" class="tsd-kind-icon">error<wbr/>Monitor</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#addListener" class="tsd-kind-icon">add<wbr/>Listener</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#emit" class="tsd-kind-icon">emit</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#eventNames" class="tsd-kind-icon">event<wbr/>Names</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#getMaxListeners" class="tsd-kind-icon">get<wbr/>Max<wbr/>Listeners</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#listenerCount" class="tsd-kind-icon">listener<wbr/>Count</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#listeners" class="tsd-kind-icon">listeners</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#off" class="tsd-kind-icon">off</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#on" class="tsd-kind-icon">on</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#once" class="tsd-kind-icon">once</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#prependListener" class="tsd-kind-icon">prepend<wbr/>Listener</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#prependOnceListener" class="tsd-kind-icon">prepend<wbr/>Once<wbr/>Listener</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#rawListeners" class="tsd-kind-icon">raw<wbr/>Listeners</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#removeAllListeners" class="tsd-kind-icon">remove<wbr/>All<wbr/>Listeners</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#removeListener" class="tsd-kind-icon">remove<wbr/>Listener</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><a href="_internal_.EventEmitter-1.html#setMaxListeners" class="tsd-kind-icon">set<wbr/>Max<wbr/>Listeners</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-static tsd-is-external"><a href="_internal_.EventEmitter-1.html#getEventListeners" class="tsd-kind-icon">get<wbr/>Event<wbr/>Listeners</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external"><a href="_internal_.EventEmitter-1.html#listenerCount-1" class="tsd-kind-icon">listener<wbr/>Count</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external"><a href="_internal_.EventEmitter-1.html#on-1" class="tsd-kind-icon">on</a></li><li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external"><a href="_internal_.EventEmitter-1.html#once-1" class="tsd-kind-icon">once</a></li></ul></li></ul></nav></div></div></div><footer class=""><div class="container"><h2>Legend</h2><div class="tsd-legend-group"><ul class="tsd-legend"><li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li><li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li></ul></div><h2>Settings</h2><p>Theme <select id="theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></p></div></footer><div class="overlay"></div><script src="../assets/main.js"></script></body></html>