mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
322 lines
212 KiB
HTML
322 lines
212 KiB
HTML
<!DOCTYPE html><html class="default" lang="en" data-base="../"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>EventEmitter | trilium</title><meta name="description" content="Documentation for trilium"/><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 defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script><script async src="../assets/hierarchy.js" id="tsd-hierarchy-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="../index.html" class="title">trilium</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb" aria-label="Breadcrumb"><li><a href="../modules/backend_script_entrypoint.html">backend_script_entrypoint</a></li><li><a href="../modules/backend_script_entrypoint._internal_.html"><internal></a></li><li><a href="" aria-current="page">EventEmitter</a></li></ul><h1>Class EventEmitter<T></h1></div><section class="tsd-panel tsd-comment"><div class="tsd-comment tsd-typography"><p>The <code>EventEmitter</code> class is defined and exposed by the <code>node:events</code> module:</p>
|
||
<pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">EventEmitter</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span>
|
||
</code><button type="button">Copy</button></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><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since">Since<a href="#since" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v0.1.26</p>
|
||
</div></div></section><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="t"><span class="tsd-kind-type-parameter">T</span> <span class="tsd-signature-keyword">extends</span> <a href="../types/backend_script_entrypoint._internal_.EventMap.html" class="tsd-signature-type tsd-kind-type-alias">EventMap</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span> = <a href="../types/backend_script_entrypoint._internal_.DefaultEventMap.html" class="tsd-signature-type tsd-kind-type-alias">DefaultEventMap</a></span></li></ul></section><section class="tsd-panel tsd-hierarchy" data-refl="3421"><h4>Hierarchy (<a href="../hierarchy.html#backend_script_entrypoint.<internal>.EventEmitter">View Summary</a>)</h4><ul class="tsd-hierarchy"><li class="tsd-hierarchy-item"><a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html" class="tsd-signature-type tsd-kind-interface">EventEmitter</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><ul class="tsd-hierarchy"><li class="tsd-hierarchy-item"><span class="tsd-hierarchy-target">EventEmitter</span><ul class="tsd-hierarchy"><li class="tsd-hierarchy-item"><a href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html" class="tsd-signature-type tsd-kind-class">Parser</a></li><li class="tsd-hierarchy-item"><a href="backend_script_entrypoint._internal_.EventEmitter.EventEmitterAsyncResource.html" class="tsd-signature-type tsd-kind-class">EventEmitterAsyncResource</a></li></ul></li></ul></li></ul></section><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/events.d.ts:102</li><li>Defined in node_modules/@types/node/events.d.ts:133</li><li>Defined in node_modules/@types/node/events.d.ts:501</li></ul></aside><section class="tsd-panel-group tsd-index-group"><section class="tsd-panel tsd-index-panel"><details class="tsd-index-content tsd-accordion" open><summary class="tsd-accordion-summary tsd-index-summary"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronSmall"></use></svg><h5 class="tsd-index-heading uppercase">Index</h5></summary><div class="tsd-accordion-details"><section class="tsd-index-section"><h3 class="tsd-index-heading">Constructors</h3><div class="tsd-index-list"><a href="#constructor" class="tsd-index-link tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Constructor"><use href="../assets/icons.svg#icon-512"></use></svg><span>constructor</span></a>
|
||
</div></section><section class="tsd-index-section"><h3 class="tsd-index-heading">Properties</h3><div class="tsd-index-list"><a href="#capturerejections" class="tsd-index-link tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Property"><use href="../assets/icons.svg#icon-1024"></use></svg><span>capture<wbr/>Rejections</span></a>
|
||
<a href="#capturerejectionsymbol" class="tsd-index-link tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Property"><use href="../assets/icons.svg#icon-1024"></use></svg><span>capture<wbr/>Rejection<wbr/>Symbol</span></a>
|
||
<a href="#defaultmaxlisteners" class="tsd-index-link tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Property"><use href="../assets/icons.svg#icon-1024"></use></svg><span>default<wbr/>Max<wbr/>Listeners</span></a>
|
||
<a href="#errormonitor" class="tsd-index-link tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Property"><use href="../assets/icons.svg#icon-1024"></use></svg><span>error<wbr/>Monitor</span></a>
|
||
</div></section><section class="tsd-index-section"><h3 class="tsd-index-heading">Methods</h3><div class="tsd-index-list"><a href="#capturerejectionsymbol-1" class="tsd-index-link tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>[capture<wbr/>Rejection<wbr/>Symbol]?</span></a>
|
||
<a href="#addlistener" class="tsd-index-link tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>add<wbr/>Listener</span></a>
|
||
<a href="#emit" class="tsd-index-link tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>emit</span></a>
|
||
<a href="#eventnames" class="tsd-index-link tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>event<wbr/>Names</span></a>
|
||
<a href="#getmaxlisteners" class="tsd-index-link tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>get<wbr/>Max<wbr/>Listeners</span></a>
|
||
<a href="#listenercount" class="tsd-index-link tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>listener<wbr/>Count</span></a>
|
||
<a href="#listeners" class="tsd-index-link tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>listeners</span></a>
|
||
<a href="#off" class="tsd-index-link tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>off</span></a>
|
||
<a href="#on" class="tsd-index-link tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>on</span></a>
|
||
<a href="#once" class="tsd-index-link tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>once</span></a>
|
||
<a href="#prependlistener" class="tsd-index-link tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>prepend<wbr/>Listener</span></a>
|
||
<a href="#prependoncelistener" class="tsd-index-link tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>prepend<wbr/>Once<wbr/>Listener</span></a>
|
||
<a href="#rawlisteners" class="tsd-index-link tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>raw<wbr/>Listeners</span></a>
|
||
<a href="#removealllisteners" class="tsd-index-link tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>remove<wbr/>All<wbr/>Listeners</span></a>
|
||
<a href="#removelistener" class="tsd-index-link tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>remove<wbr/>Listener</span></a>
|
||
<a href="#setmaxlisteners" class="tsd-index-link tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>set<wbr/>Max<wbr/>Listeners</span></a>
|
||
<a href="#addabortlistener" class="tsd-index-link tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>add<wbr/>Abort<wbr/>Listener</span></a>
|
||
<a href="#geteventlisteners" class="tsd-index-link tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>get<wbr/>Event<wbr/>Listeners</span></a>
|
||
<a href="#getmaxlisteners-2" class="tsd-index-link tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>get<wbr/>Max<wbr/>Listeners</span></a>
|
||
<a href="#listenercount-2" class="tsd-index-link deprecated tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>listener<wbr/>Count</span></a>
|
||
<a href="#on-2" class="tsd-index-link tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>on</span></a>
|
||
<a href="#once-2" class="tsd-index-link tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>once</span></a>
|
||
<a href="#setmaxlisteners-2" class="tsd-index-link tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>set<wbr/>Max<wbr/>Listeners</span></a>
|
||
</div></section></div></details></section></section><details class="tsd-panel-group tsd-member-group tsd-accordion" open><summary class="tsd-accordion-summary" data-key="section-Constructors"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h2>Constructors</h2></summary><section><section class="tsd-panel tsd-member tsd-is-external"><h3 class="tsd-anchor-link" id="constructor"><span>constructor</span><a href="#constructor" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-external"><li class="tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="constructoreventemitter"><span class="tsd-signature-keyword">new</span> <span class="tsd-kind-constructor-signature">EventEmitter</span><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a> <span class="tsd-signature-keyword">extends</span> <a href="../types/backend_script_entrypoint._internal_.EventMap.html" class="tsd-signature-type tsd-kind-type-alias">EventMap</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span> <span class="tsd-signature-symbol">=</span> <a href="../types/backend_script_entrypoint._internal_.DefaultEventMap.html" class="tsd-signature-type tsd-kind-type-alias">DefaultEventMap</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">(</span><br/> <span class="tsd-kind-parameter">options</span><span class="tsd-signature-symbol">?:</span> <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitterOptions.html" class="tsd-signature-type tsd-kind-interface">EventEmitterOptions</a><span class="tsd-signature-symbol">,</span><br/><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <a href="" class="tsd-signature-type tsd-kind-class">EventEmitter</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><a href="#constructoreventemitter" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="constructoreventemittert"><span class="tsd-kind-type-parameter">T</span> <span class="tsd-signature-keyword">extends</span> <a href="../types/backend_script_entrypoint._internal_.EventMap.html" class="tsd-signature-type tsd-kind-type-alias">EventMap</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span> = <a href="../types/backend_script_entrypoint._internal_.DefaultEventMap.html" class="tsd-signature-type tsd-kind-type-alias">DefaultEventMap</a></span></li></ul></section><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><code class="tsd-tag">Optional</code><span class="tsd-kind-parameter">options</span>: <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitterOptions.html" class="tsd-signature-type tsd-kind-interface">EventEmitterOptions</a></span></li></ul></div><h4 class="tsd-returns-title">Returns <a href="" class="tsd-signature-type tsd-kind-class">EventEmitter</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></h4><aside class="tsd-sources"><p>Inherited from NodeJS.EventEmitter<T>.constructor</p><ul><li>Defined in node_modules/@types/node/events.d.ts:134</li></ul></aside></div></li></ul></section></section></details><details class="tsd-panel-group tsd-member-group tsd-accordion" open><summary class="tsd-accordion-summary" data-key="section-Properties"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h2>Properties</h2></summary><section><section class="tsd-panel tsd-member tsd-is-external"><h3 class="tsd-anchor-link" id="capturerejections"><code class="tsd-tag">Static</code><span>capture<wbr/>Rejections</span><a href="#capturerejections" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">captureRejections</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span></div><div class="tsd-comment tsd-typography"><p>Value: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type">boolean</a></p>
|
||
<p>Change the default <code>captureRejections</code> option on all new <code>EventEmitter</code> objects.</p>
|
||
</div><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-1">Since<a href="#since-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v13.4.0, v12.16.0</p>
|
||
</div></div><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/events.d.ts:459</li></ul></aside></section><section class="tsd-panel tsd-member tsd-is-external"><h3 class="tsd-anchor-link" id="capturerejectionsymbol"><code class="tsd-tag">Static</code> <code class="tsd-tag">Readonly</code><span>capture<wbr/>Rejection<wbr/>Symbol</span><a href="#capturerejectionsymbol" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">captureRejectionSymbol</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-keyword">typeof</span> <a href="#capturerejectionsymbol" class="tsd-signature-type tsd-kind-property">captureRejectionSymbol</a></div><div class="tsd-comment tsd-typography"><p>Value: <code>Symbol.for('nodejs.rejection')</code></p>
|
||
<p>See how to write a custom <code>rejection handler</code>.</p>
|
||
</div><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-2">Since<a href="#since-2" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v13.4.0, v12.16.0</p>
|
||
</div></div><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/events.d.ts:452</li></ul></aside></section><section class="tsd-panel tsd-member tsd-is-external"><h3 class="tsd-anchor-link" id="defaultmaxlisteners"><code class="tsd-tag">Static</code><span>default<wbr/>Max<wbr/>Listeners</span><a href="#defaultmaxlisteners" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">defaultMaxListeners</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div><div class="tsd-comment tsd-typography"><p>By default, a maximum of <code>10</code> listeners can be registered for any single
|
||
event. This limit can be changed for individual <code>EventEmitter</code> instances
|
||
using the <code>emitter.setMaxListeners(n)</code> method. To change the default
|
||
for <em>all</em><code>EventEmitter</code> instances, the <code>events.defaultMaxListeners</code> property
|
||
can be used. If this value is not a positive number, a <code>RangeError</code> is thrown.</p>
|
||
<p>Take caution when setting the <code>events.defaultMaxListeners</code> because the
|
||
change affects <em>all</em> <code>EventEmitter</code> instances, including those created before
|
||
the change is made. However, calling <code>emitter.setMaxListeners(n)</code> still has
|
||
precedence over <code>events.defaultMaxListeners</code>.</p>
|
||
<p>This is not a hard limit. The <code>EventEmitter</code> instance will allow
|
||
more listeners to be added but will output a trace warning to stderr indicating
|
||
that a "possible EventEmitter memory leak" has been detected. For any single
|
||
<code>EventEmitter</code>, the <code>emitter.getMaxListeners()</code> and <code>emitter.setMaxListeners()</code> methods can be used to
|
||
temporarily avoid this warning:</p>
|
||
<pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">EventEmitter</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">emitter</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><span class="hl-5">emitter</span><span class="hl-1">.</span><span class="hl-0">setMaxListeners</span><span class="hl-1">(</span><span class="hl-5">emitter</span><span class="hl-1">.</span><span class="hl-0">getMaxListeners</span><span class="hl-1">() + </span><span class="hl-9">1</span><span class="hl-1">);</span><br/><span class="hl-5">emitter</span><span class="hl-1">.</span><span class="hl-0">once</span><span class="hl-1">(</span><span class="hl-3">'event'</span><span class="hl-1">, () </span><span class="hl-2">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-6">// do stuff</span><br/><span class="hl-1"> </span><span class="hl-5">emitter</span><span class="hl-1">.</span><span class="hl-0">setMaxListeners</span><span class="hl-1">(</span><span class="hl-5">Math</span><span class="hl-1">.</span><span class="hl-0">max</span><span class="hl-1">(</span><span class="hl-5">emitter</span><span class="hl-1">.</span><span class="hl-0">getMaxListeners</span><span class="hl-1">() - </span><span class="hl-9">1</span><span class="hl-1">, </span><span class="hl-9">0</span><span class="hl-1">));</span><br/><span class="hl-1">});</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
<p>The <code>--trace-warnings</code> command-line flag can be used to display the
|
||
stack trace for such warnings.</p>
|
||
<p>The emitted warning can be inspected with <code>process.on('warning')</code> and will
|
||
have the additional <code>emitter</code>, <code>type</code>, and <code>count</code> properties, referring to
|
||
the event emitter instance, the event's name and the number of attached
|
||
listeners, respectively.
|
||
Its <code>name</code> property is set to <code>'MaxListenersExceededWarning'</code>.</p>
|
||
</div><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-3">Since<a href="#since-3" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v0.11.2</p>
|
||
</div></div><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/events.d.ts:498</li></ul></aside></section><section class="tsd-panel tsd-member tsd-is-external"><h3 class="tsd-anchor-link" id="errormonitor"><code class="tsd-tag">Static</code> <code class="tsd-tag">Readonly</code><span>error<wbr/>Monitor</span><a href="#errormonitor" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">errorMonitor</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-keyword">typeof</span> <a href="#errormonitor" class="tsd-signature-type tsd-kind-property">errorMonitor</a></div><div class="tsd-comment tsd-typography"><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>
|
||
<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 class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-4">Since<a href="#since-4" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v13.6.0, v12.17.0</p>
|
||
</div></div><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/events.d.ts:445</li></ul></aside></section></section></details><details class="tsd-panel-group tsd-member-group tsd-accordion" open><summary class="tsd-accordion-summary" data-key="section-Methods"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h2>Methods</h2></summary><section><section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><h3 class="tsd-anchor-link" id="capturerejectionsymbol-1"><code class="tsd-tag">Optional</code><span>[capture<wbr/>Rejection<wbr/>Symbol]</span><a href="#capturerejectionsymbol-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-inherited tsd-is-external"><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="capturerejectionsymbol-2"><span class="tsd-kind-call-signature">"[captureRejectionSymbol]"</span><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#capturerejectionsymbolk">K</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">(</span><br/> <span class="tsd-kind-parameter">error</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">Error</span><span class="tsd-signature-symbol">,</span><br/> <span class="tsd-kind-parameter">event</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#capturerejectionsymbolk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">,</span><br/> <span class="tsd-signature-symbol">...</span><span class="tsd-kind-parameter">args</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Args.html" class="tsd-signature-type tsd-kind-type-alias">Args</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#capturerejectionsymbolk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">,</span><br/><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">void</span><a href="#capturerejectionsymbol-2" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="capturerejectionsymbolk"><span class="tsd-kind-type-parameter">K</span></span></li></ul></section><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">error</span>: <span class="tsd-signature-type">Error</span></span></li><li><span><span class="tsd-kind-parameter">event</span>: <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#capturerejectionsymbolk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></span></li><li><span><span class="tsd-signature-symbol">...</span><span class="tsd-kind-parameter">args</span>: <a href="../types/backend_script_entrypoint._internal_.Args.html" class="tsd-signature-type tsd-kind-type-alias">Args</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#capturerejectionsymbolk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></span></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html">EventEmitter</a>.<a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html#capturerejectionsymbol">[captureRejectionSymbol]</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:136</li></ul></aside></div></li></ul></section><section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><h3 class="tsd-anchor-link" id="addlistener"><span>add<wbr/>Listener</span><a href="#addlistener" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-inherited tsd-is-external"><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="addlistener-1"><span class="tsd-kind-call-signature">addListener</span><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#addlistenerk">K</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">eventName</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#addlistenerk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">,</span> <span class="tsd-kind-parameter">listener</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Listener.html" class="tsd-signature-type tsd-kind-type-alias">Listener</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#addlistenerk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">this</span><a href="#addlistener-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><p>Alias for <code>emitter.on(eventName, listener)</code>.</p>
|
||
</div><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="addlistenerk"><span class="tsd-kind-type-parameter">K</span></span></li></ul></section><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">eventName</span>: <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#addlistenerk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></span></li><li><span><span class="tsd-kind-parameter">listener</span>: <a href="../types/backend_script_entrypoint._internal_.Listener.html" class="tsd-signature-type tsd-kind-type-alias">Listener</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#addlistenerk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></span></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">this</span></h4><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-5">Since<a href="#since-5" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v0.1.26</p>
|
||
</div></div><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html">EventEmitter</a>.<a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html#addlistener">addListener</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:597</li></ul></aside></div></li></ul></section><section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><h3 class="tsd-anchor-link" id="emit"><span>emit</span><a href="#emit" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-inherited tsd-is-external"><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="emit-1"><span class="tsd-kind-call-signature">emit</span><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#emitk">K</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">eventName</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#emitk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">,</span> <span class="tsd-signature-symbol">...</span><span class="tsd-kind-parameter">args</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Args.html" class="tsd-signature-type tsd-kind-type-alias">Args</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#emitk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><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><a href="#emit-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><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>
|
||
<p>Returns <code>true</code> if the event had listeners, <code>false</code> otherwise.</p>
|
||
<pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">EventEmitter</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">myEmitter</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><br/><span class="hl-6">// First listener</span><br/><span class="hl-5">myEmitter</span><span class="hl-1">.</span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-3">'event'</span><span class="hl-1">, </span><span class="hl-2">function</span><span class="hl-1"> </span><span class="hl-0">firstListener</span><span class="hl-1">() {</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'Helloooo! first listener'</span><span class="hl-1">);</span><br/><span class="hl-1">});</span><br/><span class="hl-6">// Second listener</span><br/><span class="hl-5">myEmitter</span><span class="hl-1">.</span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-3">'event'</span><span class="hl-1">, </span><span class="hl-2">function</span><span class="hl-1"> </span><span class="hl-0">secondListener</span><span class="hl-1">(</span><span class="hl-5">arg1</span><span class="hl-1">, </span><span class="hl-5">arg2</span><span class="hl-1">) {</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">`event with parameters </span><span class="hl-2">${</span><span class="hl-5">arg1</span><span class="hl-2">}</span><span class="hl-3">, </span><span class="hl-2">${</span><span class="hl-5">arg2</span><span class="hl-2">}</span><span class="hl-3"> in second listener`</span><span class="hl-1">);</span><br/><span class="hl-1">});</span><br/><span class="hl-6">// Third listener</span><br/><span class="hl-5">myEmitter</span><span class="hl-1">.</span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-3">'event'</span><span class="hl-1">, </span><span class="hl-2">function</span><span class="hl-1"> </span><span class="hl-0">thirdListener</span><span class="hl-1">(...</span><span class="hl-5">args</span><span class="hl-1">) {</span><br/><span class="hl-1"> </span><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">parameters</span><span class="hl-1"> = </span><span class="hl-5">args</span><span class="hl-1">.</span><span class="hl-0">join</span><span class="hl-1">(</span><span class="hl-3">', '</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">`event with parameters </span><span class="hl-2">${</span><span class="hl-5">parameters</span><span class="hl-2">}</span><span class="hl-3"> in third listener`</span><span class="hl-1">);</span><br/><span class="hl-1">});</span><br/><br/><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-5">myEmitter</span><span class="hl-1">.</span><span class="hl-0">listeners</span><span class="hl-1">(</span><span class="hl-3">'event'</span><span class="hl-1">));</span><br/><br/><span class="hl-5">myEmitter</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'event'</span><span class="hl-1">, </span><span class="hl-9">1</span><span class="hl-1">, </span><span class="hl-9">2</span><span class="hl-1">, </span><span class="hl-9">3</span><span class="hl-1">, </span><span class="hl-9">4</span><span class="hl-1">, </span><span class="hl-9">5</span><span class="hl-1">);</span><br/><br/><span class="hl-6">// Prints:</span><br/><span class="hl-6">// [</span><br/><span class="hl-6">// [Function: firstListener],</span><br/><span class="hl-6">// [Function: secondListener],</span><br/><span class="hl-6">// [Function: thirdListener]</span><br/><span class="hl-6">// ]</span><br/><span class="hl-6">// Helloooo! first listener</span><br/><span class="hl-6">// event with parameters 1, 2 in second listener</span><br/><span class="hl-6">// event with parameters 1, 2, 3, 4, 5 in third listener</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
</div><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="emitk"><span class="tsd-kind-type-parameter">K</span></span></li></ul></section><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">eventName</span>: <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#emitk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></span></li><li><span><span class="tsd-signature-symbol">...</span><span class="tsd-kind-parameter">args</span>: <a href="../types/backend_script_entrypoint._internal_.Args.html" class="tsd-signature-type tsd-kind-type-alias">Args</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#emitk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></span></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-6">Since<a href="#since-6" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v0.1.26</p>
|
||
</div></div><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html">EventEmitter</a>.<a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html#emit">emit</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:859</li></ul></aside></div></li></ul></section><section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><h3 class="tsd-anchor-link" id="eventnames"><span>event<wbr/>Names</span><a href="#eventnames" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-inherited tsd-is-external"><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="eventnames-1"><span class="tsd-kind-call-signature">eventNames</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> <a href="../types/backend_script_entrypoint._internal_.Key2.html" class="tsd-signature-type tsd-kind-type-alias">Key2</a><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">unknown</span><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span>)<span class="tsd-signature-symbol">[]</span><a href="#eventnames-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><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>
|
||
<pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">EventEmitter</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">myEE</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><span class="hl-5">myEE</span><span class="hl-1">.</span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">, () </span><span class="hl-2">=></span><span class="hl-1"> {});</span><br/><span class="hl-5">myEE</span><span class="hl-1">.</span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-3">'bar'</span><span class="hl-1">, () </span><span class="hl-2">=></span><span class="hl-1"> {});</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">sym</span><span class="hl-1"> = </span><span class="hl-0">Symbol</span><span class="hl-1">(</span><span class="hl-3">'symbol'</span><span class="hl-1">);</span><br/><span class="hl-5">myEE</span><span class="hl-1">.</span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-5">sym</span><span class="hl-1">, () </span><span class="hl-2">=></span><span class="hl-1"> {});</span><br/><br/><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-5">myEE</span><span class="hl-1">.</span><span class="hl-0">eventNames</span><span class="hl-1">());</span><br/><span class="hl-6">// Prints: [ 'foo', 'bar', Symbol(symbol) ]</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
</div><h4 class="tsd-returns-title">Returns ((<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> <a href="../types/backend_script_entrypoint._internal_.Key2.html" class="tsd-signature-type tsd-kind-type-alias">Key2</a><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">unknown</span><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span>)<span class="tsd-signature-symbol">[]</span></h4><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-7">Since<a href="#since-7" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v6.0.0</p>
|
||
</div></div><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html">EventEmitter</a>.<a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html#eventnames">eventNames</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:922</li></ul></aside></div></li></ul></section><section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><h3 class="tsd-anchor-link" id="getmaxlisteners"><span>get<wbr/>Max<wbr/>Listeners</span><a href="#getmaxlisteners" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-inherited tsd-is-external"><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="getmaxlisteners-1"><span class="tsd-kind-call-signature">getMaxListeners</span><span class="tsd-signature-symbol">()</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span><a href="#getmaxlisteners-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><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="#defaultmaxlisteners" class="tsd-kind-property">EventEmitter.defaultMaxListeners</a>.</p>
|
||
</div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">number</span></h4><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-8">Since<a href="#since-8" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v1.0.0</p>
|
||
</div></div><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html">EventEmitter</a>.<a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html#getmaxlisteners">getMaxListeners</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:774</li></ul></aside></div></li></ul></section><section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><h3 class="tsd-anchor-link" id="listenercount"><span>listener<wbr/>Count</span><a href="#listenercount" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-inherited tsd-is-external"><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="listenercount-1"><span class="tsd-kind-call-signature">listenerCount</span><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#listenercountk">K</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">(</span><br/> <span class="tsd-kind-parameter">eventName</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#listenercountk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">,</span><br/> <span class="tsd-kind-parameter">listener</span><span class="tsd-signature-symbol">?:</span> <a href="../types/backend_script_entrypoint._internal_.Listener.html" class="tsd-signature-type tsd-kind-type-alias">Listener</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#listenercountk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">,</span> <span class="tsd-signature-type">Function</span><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">,</span><br/><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span><a href="#listenercount-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><p>Returns the number of listeners listening for the event named <code>eventName</code>.
|
||
If <code>listener</code> is provided, it will return how many times the listener is found
|
||
in the list of the listeners of the event.</p>
|
||
</div><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="listenercountk"><span class="tsd-kind-type-parameter">K</span></span></li></ul></section><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">eventName</span>: <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#listenercountk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></span><div class="tsd-comment tsd-typography"><p>The name of the event being listened for</p>
|
||
</div><div class="tsd-comment tsd-typography"></div></li><li><span><code class="tsd-tag">Optional</code><span class="tsd-kind-parameter">listener</span>: <a href="../types/backend_script_entrypoint._internal_.Listener.html" class="tsd-signature-type tsd-kind-type-alias">Listener</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#listenercountk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">,</span> <span class="tsd-signature-type">Function</span><span class="tsd-signature-symbol">></span></span><div class="tsd-comment tsd-typography"><p>The event handler function</p>
|
||
</div><div class="tsd-comment tsd-typography"></div></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">number</span></h4><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-9">Since<a href="#since-9" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v3.2.0</p>
|
||
</div></div><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html">EventEmitter</a>.<a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html#listenercount">listenerCount</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:868</li></ul></aside></div></li></ul></section><section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><h3 class="tsd-anchor-link" id="listeners"><span>listeners</span><a href="#listeners" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-inherited tsd-is-external"><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="listeners-1"><span class="tsd-kind-call-signature">listeners</span><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#listenersk">K</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">eventName</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#listenersk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Listener.html" class="tsd-signature-type tsd-kind-type-alias">Listener</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#listenersk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">,</span> <span class="tsd-signature-type">Function</span><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">[]</span><a href="#listeners-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><p>Returns a copy of the array of listeners for the event named <code>eventName</code>.</p>
|
||
<pre><code class="js"><span class="hl-5">server</span><span class="hl-1">.</span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-3">'connection'</span><span class="hl-1">, (</span><span class="hl-5">stream</span><span class="hl-1">) </span><span class="hl-2">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'someone connected!'</span><span class="hl-1">);</span><br/><span class="hl-1">});</span><br/><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-5">util</span><span class="hl-1">.</span><span class="hl-0">inspect</span><span class="hl-1">(</span><span class="hl-5">server</span><span class="hl-1">.</span><span class="hl-0">listeners</span><span class="hl-1">(</span><span class="hl-3">'connection'</span><span class="hl-1">)));</span><br/><span class="hl-6">// Prints: [ [Function] ]</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
</div><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="listenersk"><span class="tsd-kind-type-parameter">K</span></span></li></ul></section><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">eventName</span>: <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#listenersk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></span></li></ul></div><h4 class="tsd-returns-title">Returns <a href="../types/backend_script_entrypoint._internal_.Listener.html" class="tsd-signature-type tsd-kind-type-alias">Listener</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#listenersk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">,</span> <span class="tsd-signature-type">Function</span><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">[]</span></h4><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-10">Since<a href="#since-10" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v0.1.26</p>
|
||
</div></div><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html">EventEmitter</a>.<a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html#listeners">listeners</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:787</li></ul></aside></div></li></ul></section><section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><h3 class="tsd-anchor-link" id="off"><span>off</span><a href="#off" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-inherited tsd-is-external"><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="off-1"><span class="tsd-kind-call-signature">off</span><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#offk">K</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">eventName</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#offk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">,</span> <span class="tsd-kind-parameter">listener</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Listener.html" class="tsd-signature-type tsd-kind-type-alias">Listener</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#offk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">this</span><a href="#off-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><p>Alias for <code>emitter.removeListener()</code>.</p>
|
||
</div><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="offk"><span class="tsd-kind-type-parameter">K</span></span></li></ul></section><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">eventName</span>: <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#offk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></span></li><li><span><span class="tsd-kind-parameter">listener</span>: <a href="../types/backend_script_entrypoint._internal_.Listener.html" class="tsd-signature-type tsd-kind-type-alias">Listener</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#offk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></span></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">this</span></h4><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-11">Since<a href="#since-11" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v10.0.0</p>
|
||
</div></div><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html">EventEmitter</a>.<a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html#off">off</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:747</li></ul></aside></div></li></ul></section><section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><h3 class="tsd-anchor-link" id="on"><span>on</span><a href="#on" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-inherited tsd-is-external"><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="on-1"><span class="tsd-kind-call-signature">on</span><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#onk">K</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">eventName</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#onk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">,</span> <span class="tsd-kind-parameter">listener</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Listener.html" class="tsd-signature-type tsd-kind-type-alias">Listener</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#onk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">this</span><a href="#on-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><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>
|
||
<pre><code class="js"><span class="hl-5">server</span><span class="hl-1">.</span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-3">'connection'</span><span class="hl-1">, (</span><span class="hl-5">stream</span><span class="hl-1">) </span><span class="hl-2">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'someone connected!'</span><span class="hl-1">);</span><br/><span class="hl-1">});</span>
|
||
</code><button type="button">Copy</button></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="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">EventEmitter</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">myEE</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><span class="hl-5">myEE</span><span class="hl-1">.</span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">, () </span><span class="hl-2">=></span><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'a'</span><span class="hl-1">));</span><br/><span class="hl-5">myEE</span><span class="hl-1">.</span><span class="hl-0">prependListener</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">, () </span><span class="hl-2">=></span><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'b'</span><span class="hl-1">));</span><br/><span class="hl-5">myEE</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">);</span><br/><span class="hl-6">// Prints:</span><br/><span class="hl-6">// b</span><br/><span class="hl-6">// a</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
</div><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="onk"><span class="tsd-kind-type-parameter">K</span></span></li></ul></section><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">eventName</span>: <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#onk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></span><div class="tsd-comment tsd-typography"><p>The name of the event.</p>
|
||
</div><div class="tsd-comment tsd-typography"></div></li><li><span><span class="tsd-kind-parameter">listener</span>: <a href="../types/backend_script_entrypoint._internal_.Listener.html" class="tsd-signature-type tsd-kind-type-alias">Listener</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#onk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></span><div class="tsd-comment tsd-typography"><p>The callback function</p>
|
||
</div><div class="tsd-comment tsd-typography"></div></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">this</span></h4><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-12">Since<a href="#since-12" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v0.1.101</p>
|
||
</div></div><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html">EventEmitter</a>.<a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html#on">on</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:629</li></ul></aside></div></li></ul></section><section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><h3 class="tsd-anchor-link" id="once"><span>once</span><a href="#once" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-inherited tsd-is-external"><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="once-1"><span class="tsd-kind-call-signature">once</span><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#oncek">K</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">eventName</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#oncek">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">,</span> <span class="tsd-kind-parameter">listener</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Listener.html" class="tsd-signature-type tsd-kind-type-alias">Listener</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#oncek">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">this</span><a href="#once-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><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>
|
||
<pre><code class="js"><span class="hl-5">server</span><span class="hl-1">.</span><span class="hl-0">once</span><span class="hl-1">(</span><span class="hl-3">'connection'</span><span class="hl-1">, (</span><span class="hl-5">stream</span><span class="hl-1">) </span><span class="hl-2">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'Ah, we have our first user!'</span><span class="hl-1">);</span><br/><span class="hl-1">});</span>
|
||
</code><button type="button">Copy</button></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="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">EventEmitter</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">myEE</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><span class="hl-5">myEE</span><span class="hl-1">.</span><span class="hl-0">once</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">, () </span><span class="hl-2">=></span><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'a'</span><span class="hl-1">));</span><br/><span class="hl-5">myEE</span><span class="hl-1">.</span><span class="hl-0">prependOnceListener</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">, () </span><span class="hl-2">=></span><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'b'</span><span class="hl-1">));</span><br/><span class="hl-5">myEE</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">);</span><br/><span class="hl-6">// Prints:</span><br/><span class="hl-6">// b</span><br/><span class="hl-6">// a</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
</div><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="oncek"><span class="tsd-kind-type-parameter">K</span></span></li></ul></section><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">eventName</span>: <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#oncek">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></span><div class="tsd-comment tsd-typography"><p>The name of the event.</p>
|
||
</div><div class="tsd-comment tsd-typography"></div></li><li><span><span class="tsd-kind-parameter">listener</span>: <a href="../types/backend_script_entrypoint._internal_.Listener.html" class="tsd-signature-type tsd-kind-type-alias">Listener</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#oncek">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></span><div class="tsd-comment tsd-typography"><p>The callback function</p>
|
||
</div><div class="tsd-comment tsd-typography"></div></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">this</span></h4><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-13">Since<a href="#since-13" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v0.3.0</p>
|
||
</div></div><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html">EventEmitter</a>.<a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html#once">once</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:659</li></ul></aside></div></li></ul></section><section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><h3 class="tsd-anchor-link" id="prependlistener"><span>prepend<wbr/>Listener</span><a href="#prependlistener" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-inherited tsd-is-external"><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="prependlistener-1"><span class="tsd-kind-call-signature">prependListener</span><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#prependlistenerk">K</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">eventName</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#prependlistenerk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">,</span> <span class="tsd-kind-parameter">listener</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Listener.html" class="tsd-signature-type tsd-kind-type-alias">Listener</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#prependlistenerk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">this</span><a href="#prependlistener-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><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>
|
||
<pre><code class="js"><span class="hl-5">server</span><span class="hl-1">.</span><span class="hl-0">prependListener</span><span class="hl-1">(</span><span class="hl-3">'connection'</span><span class="hl-1">, (</span><span class="hl-5">stream</span><span class="hl-1">) </span><span class="hl-2">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'someone connected!'</span><span class="hl-1">);</span><br/><span class="hl-1">});</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
<p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>
|
||
</div><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="prependlistenerk"><span class="tsd-kind-type-parameter">K</span></span></li></ul></section><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">eventName</span>: <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#prependlistenerk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></span><div class="tsd-comment tsd-typography"><p>The name of the event.</p>
|
||
</div><div class="tsd-comment tsd-typography"></div></li><li><span><span class="tsd-kind-parameter">listener</span>: <a href="../types/backend_script_entrypoint._internal_.Listener.html" class="tsd-signature-type tsd-kind-type-alias">Listener</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#prependlistenerk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></span><div class="tsd-comment tsd-typography"><p>The callback function</p>
|
||
</div><div class="tsd-comment tsd-typography"></div></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">this</span></h4><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-14">Since<a href="#since-14" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v6.0.0</p>
|
||
</div></div><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html">EventEmitter</a>.<a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html#prependlistener">prependListener</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:886</li></ul></aside></div></li></ul></section><section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><h3 class="tsd-anchor-link" id="prependoncelistener"><span>prepend<wbr/>Once<wbr/>Listener</span><a href="#prependoncelistener" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-inherited tsd-is-external"><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="prependoncelistener-1"><span class="tsd-kind-call-signature">prependOnceListener</span><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#prependoncelistenerk">K</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">eventName</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#prependoncelistenerk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">,</span> <span class="tsd-kind-parameter">listener</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Listener.html" class="tsd-signature-type tsd-kind-type-alias">Listener</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#prependoncelistenerk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">this</span><a href="#prependoncelistener-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><p>Adds a <strong>one-time</strong><code>listener</code> function for the event named <code>eventName</code> to the <em>beginning</em> of the listeners array. The next time <code>eventName</code> is triggered, this
|
||
listener is removed, and then invoked.</p>
|
||
<pre><code class="js"><span class="hl-5">server</span><span class="hl-1">.</span><span class="hl-0">prependOnceListener</span><span class="hl-1">(</span><span class="hl-3">'connection'</span><span class="hl-1">, (</span><span class="hl-5">stream</span><span class="hl-1">) </span><span class="hl-2">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'Ah, we have our first user!'</span><span class="hl-1">);</span><br/><span class="hl-1">});</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
<p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>
|
||
</div><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="prependoncelistenerk"><span class="tsd-kind-type-parameter">K</span></span></li></ul></section><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">eventName</span>: <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#prependoncelistenerk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></span><div class="tsd-comment tsd-typography"><p>The name of the event.</p>
|
||
</div><div class="tsd-comment tsd-typography"></div></li><li><span><span class="tsd-kind-parameter">listener</span>: <a href="../types/backend_script_entrypoint._internal_.Listener.html" class="tsd-signature-type tsd-kind-type-alias">Listener</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#prependoncelistenerk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></span><div class="tsd-comment tsd-typography"><p>The callback function</p>
|
||
</div><div class="tsd-comment tsd-typography"></div></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">this</span></h4><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-15">Since<a href="#since-15" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v6.0.0</p>
|
||
</div></div><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html">EventEmitter</a>.<a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html#prependoncelistener">prependOnceListener</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:902</li></ul></aside></div></li></ul></section><section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><h3 class="tsd-anchor-link" id="rawlisteners"><span>raw<wbr/>Listeners</span><a href="#rawlisteners" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-inherited tsd-is-external"><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="rawlisteners-1"><span class="tsd-kind-call-signature">rawListeners</span><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#rawlistenersk">K</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">eventName</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#rawlistenersk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Listener.html" class="tsd-signature-type tsd-kind-type-alias">Listener</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#rawlistenersk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">,</span> <span class="tsd-signature-type">Function</span><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">[]</span><a href="#rawlisteners-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><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>
|
||
<pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">EventEmitter</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">emitter</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><span class="hl-5">emitter</span><span class="hl-1">.</span><span class="hl-0">once</span><span class="hl-1">(</span><span class="hl-3">'log'</span><span class="hl-1">, () </span><span class="hl-2">=></span><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'log once'</span><span class="hl-1">));</span><br/><br/><span class="hl-6">// Returns a new Array with a function `onceWrapper` which has a property</span><br/><span class="hl-6">// `listener` which contains the original listener bound above</span><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">listeners</span><span class="hl-1"> = </span><span class="hl-5">emitter</span><span class="hl-1">.</span><span class="hl-0">rawListeners</span><span class="hl-1">(</span><span class="hl-3">'log'</span><span class="hl-1">);</span><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">logFnWrapper</span><span class="hl-1"> = </span><span class="hl-5">listeners</span><span class="hl-1">[</span><span class="hl-9">0</span><span class="hl-1">];</span><br/><br/><span class="hl-6">// Logs "log once" to the console and does not unbind the `once` event</span><br/><span class="hl-5">logFnWrapper</span><span class="hl-1">.</span><span class="hl-0">listener</span><span class="hl-1">();</span><br/><br/><span class="hl-6">// Logs "log once" to the console and removes the listener</span><br/><span class="hl-0">logFnWrapper</span><span class="hl-1">();</span><br/><br/><span class="hl-5">emitter</span><span class="hl-1">.</span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-3">'log'</span><span class="hl-1">, () </span><span class="hl-2">=></span><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'log persistently'</span><span class="hl-1">));</span><br/><span class="hl-6">// Will return a new Array with a single function bound by `.on()` above</span><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">newListeners</span><span class="hl-1"> = </span><span class="hl-5">emitter</span><span class="hl-1">.</span><span class="hl-0">rawListeners</span><span class="hl-1">(</span><span class="hl-3">'log'</span><span class="hl-1">);</span><br/><br/><span class="hl-6">// Logs "log persistently" twice</span><br/><span class="hl-5">newListeners</span><span class="hl-1">[</span><span class="hl-9">0</span><span class="hl-1">]();</span><br/><span class="hl-5">emitter</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'log'</span><span class="hl-1">);</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
</div><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="rawlistenersk"><span class="tsd-kind-type-parameter">K</span></span></li></ul></section><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">eventName</span>: <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#rawlistenersk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></span></li></ul></div><h4 class="tsd-returns-title">Returns <a href="../types/backend_script_entrypoint._internal_.Listener.html" class="tsd-signature-type tsd-kind-type-alias">Listener</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#rawlistenersk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">,</span> <span class="tsd-signature-type">Function</span><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">[]</span></h4><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-16">Since<a href="#since-16" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v9.4.0</p>
|
||
</div></div><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html">EventEmitter</a>.<a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html#rawlisteners">rawListeners</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:818</li></ul></aside></div></li></ul></section><section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><h3 class="tsd-anchor-link" id="removealllisteners"><span>remove<wbr/>All<wbr/>Listeners</span><a href="#removealllisteners" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-inherited tsd-is-external"><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="removealllisteners-1"><span class="tsd-kind-call-signature">removeAllListeners</span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">eventName</span><span class="tsd-signature-symbol">?:</span> <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">unknown</span><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">this</span><a href="#removealllisteners-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><p>Removes all listeners, or those of the specified <code>eventName</code>.</p>
|
||
<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><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><code class="tsd-tag">Optional</code><span class="tsd-kind-parameter">eventName</span>: <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">unknown</span><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></span></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">this</span></h4><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-17">Since<a href="#since-17" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v0.1.26</p>
|
||
</div></div><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html">EventEmitter</a>.<a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html#removealllisteners">removeAllListeners</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:758</li></ul></aside></div></li></ul></section><section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><h3 class="tsd-anchor-link" id="removelistener"><span>remove<wbr/>Listener</span><a href="#removelistener" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-inherited tsd-is-external"><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="removelistener-1"><span class="tsd-kind-call-signature">removeListener</span><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#removelistenerk">K</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">eventName</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#removelistenerk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">,</span> <span class="tsd-kind-parameter">listener</span><span class="tsd-signature-symbol">:</span> <a href="../types/backend_script_entrypoint._internal_.Listener.html" class="tsd-signature-type tsd-kind-type-alias">Listener</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#removelistenerk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">this</span><a href="#removelistener-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><p>Removes the specified <code>listener</code> from the listener array for the event named <code>eventName</code>.</p>
|
||
<pre><code class="js"><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-0">callback</span><span class="hl-1"> = (</span><span class="hl-5">stream</span><span class="hl-1">) </span><span class="hl-2">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'someone connected!'</span><span class="hl-1">);</span><br/><span class="hl-1">};</span><br/><span class="hl-5">server</span><span class="hl-1">.</span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-3">'connection'</span><span class="hl-1">, </span><span class="hl-5">callback</span><span class="hl-1">);</span><br/><span class="hl-6">// ...</span><br/><span class="hl-5">server</span><span class="hl-1">.</span><span class="hl-0">removeListener</span><span class="hl-1">(</span><span class="hl-3">'connection'</span><span class="hl-1">, </span><span class="hl-5">callback</span><span class="hl-1">);</span>
|
||
</code><button type="button">Copy</button></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 <em>before</em> the last listener finishes execution
|
||
will not remove them from<code>emit()</code> in progress. Subsequent events behave as expected.</p>
|
||
<pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">EventEmitter</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><span class="hl-2">class</span><span class="hl-1"> </span><span class="hl-8">MyEmitter</span><span class="hl-1"> </span><span class="hl-2">extends</span><span class="hl-1"> </span><span class="hl-8">EventEmitter</span><span class="hl-1"> {}</span><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">myEmitter</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">MyEmitter</span><span class="hl-1">();</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-0">callbackA</span><span class="hl-1"> = () </span><span class="hl-2">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'A'</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-5">myEmitter</span><span class="hl-1">.</span><span class="hl-0">removeListener</span><span class="hl-1">(</span><span class="hl-3">'event'</span><span class="hl-1">, </span><span class="hl-5">callbackB</span><span class="hl-1">);</span><br/><span class="hl-1">};</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-0">callbackB</span><span class="hl-1"> = () </span><span class="hl-2">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'B'</span><span class="hl-1">);</span><br/><span class="hl-1">};</span><br/><br/><span class="hl-5">myEmitter</span><span class="hl-1">.</span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-3">'event'</span><span class="hl-1">, </span><span class="hl-5">callbackA</span><span class="hl-1">);</span><br/><br/><span class="hl-5">myEmitter</span><span class="hl-1">.</span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-3">'event'</span><span class="hl-1">, </span><span class="hl-5">callbackB</span><span class="hl-1">);</span><br/><br/><span class="hl-6">// callbackA removes listener callbackB but it will still be called.</span><br/><span class="hl-6">// Internal listener array at time of emit [callbackA, callbackB]</span><br/><span class="hl-5">myEmitter</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'event'</span><span class="hl-1">);</span><br/><span class="hl-6">// Prints:</span><br/><span class="hl-6">// A</span><br/><span class="hl-6">// B</span><br/><br/><span class="hl-6">// callbackB is now removed.</span><br/><span class="hl-6">// Internal listener array [callbackA]</span><br/><span class="hl-5">myEmitter</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'event'</span><span class="hl-1">);</span><br/><span class="hl-6">// Prints:</span><br/><span class="hl-6">// A</span>
|
||
</code><button type="button">Copy</button></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="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">EventEmitter</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">ee</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><br/><span class="hl-2">function</span><span class="hl-1"> </span><span class="hl-0">pong</span><span class="hl-1">() {</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'pong'</span><span class="hl-1">);</span><br/><span class="hl-1">}</span><br/><br/><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-3">'ping'</span><span class="hl-1">, </span><span class="hl-5">pong</span><span class="hl-1">);</span><br/><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">once</span><span class="hl-1">(</span><span class="hl-3">'ping'</span><span class="hl-1">, </span><span class="hl-5">pong</span><span class="hl-1">);</span><br/><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">removeListener</span><span class="hl-1">(</span><span class="hl-3">'ping'</span><span class="hl-1">, </span><span class="hl-5">pong</span><span class="hl-1">);</span><br/><br/><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'ping'</span><span class="hl-1">);</span><br/><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'ping'</span><span class="hl-1">);</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
<p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>
|
||
</div><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="removelistenerk"><span class="tsd-kind-type-parameter">K</span></span></li></ul></section><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">eventName</span>: <a href="../types/backend_script_entrypoint._internal_.Key.html" class="tsd-signature-type tsd-kind-type-alias">Key</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#removelistenerk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></span></li><li><span><span class="tsd-kind-parameter">listener</span>: <a href="../types/backend_script_entrypoint._internal_.Listener.html" class="tsd-signature-type tsd-kind-type-alias">Listener</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="backend_script_entrypoint._internal_.node_modules__types_xml2js.Parser.html#removelistenerk">K</a><span class="tsd-signature-symbol">,</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#constructoreventemittert">T</a><span class="tsd-signature-symbol">></span></span></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">this</span></h4><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-18">Since<a href="#since-18" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v0.1.26</p>
|
||
</div></div><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html">EventEmitter</a>.<a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html#removelistener">removeListener</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:742</li></ul></aside></div></li></ul></section><section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><h3 class="tsd-anchor-link" id="setmaxlisteners"><span>set<wbr/>Max<wbr/>Listeners</span><a href="#setmaxlisteners" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-inherited tsd-is-external"><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="setmaxlisteners-1"><span class="tsd-kind-call-signature">setMaxListeners</span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">n</span><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> <span class="tsd-signature-type">this</span><a href="#setmaxlisteners-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><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>
|
||
<p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>
|
||
</div><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">n</span>: <span class="tsd-signature-type">number</span></span></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">this</span></h4><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-19">Since<a href="#since-19" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v0.3.5</p>
|
||
</div></div><aside class="tsd-sources"><p>Inherited from <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html">EventEmitter</a>.<a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html#setmaxlisteners">setMaxListeners</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:768</li></ul></aside></div></li></ul></section><section class="tsd-panel tsd-member tsd-is-external"><h3 class="tsd-anchor-link" id="addabortlistener"><code class="tsd-tag">Static</code><span>add<wbr/>Abort<wbr/>Listener</span><a href="#addabortlistener" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-external"><li class="tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="addabortlistener-1"><span class="tsd-kind-call-signature">addAbortListener</span><span class="tsd-signature-symbol">(</span><br/> <span class="tsd-kind-parameter">signal</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">AbortSignal</span><span class="tsd-signature-symbol">,</span><br/> <span class="tsd-kind-parameter">resource</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">event</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">Event</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><br/><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <a href="../interfaces/backend_script_entrypoint._internal_.Disposable.html" class="tsd-signature-type tsd-kind-interface">Disposable</a><a href="#addabortlistener-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><code class="tsd-tag">Experimental</code><div class="tsd-comment tsd-typography"><p>Listens once to the <code>abort</code> event on the provided <code>signal</code>.</p>
|
||
<p>Listening to the <code>abort</code> event on abort signals is unsafe and may
|
||
lead to resource leaks since another third party with the signal can
|
||
call <code>e.stopImmediatePropagation()</code>. Unfortunately Node.js cannot change
|
||
this since it would violate the web standard. Additionally, the original
|
||
API makes it easy to forget to remove listeners.</p>
|
||
<p>This API allows safely using <code>AbortSignal</code>s in Node.js APIs by solving these
|
||
two issues by listening to the event such that <code>stopImmediatePropagation</code> does
|
||
not prevent the listener from running.</p>
|
||
<p>Returns a disposable so that it may be unsubscribed from more easily.</p>
|
||
<pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">addAbortListener</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><br/><span class="hl-2">function</span><span class="hl-1"> </span><span class="hl-0">example</span><span class="hl-1">(</span><span class="hl-5">signal</span><span class="hl-1">) {</span><br/><span class="hl-1"> </span><span class="hl-2">let</span><span class="hl-1"> </span><span class="hl-5">disposable</span><span class="hl-1">;</span><br/><span class="hl-1"> </span><span class="hl-4">try</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">signal</span><span class="hl-1">.</span><span class="hl-0">addEventListener</span><span class="hl-1">(</span><span class="hl-3">'abort'</span><span class="hl-1">, (</span><span class="hl-5">e</span><span class="hl-1">) </span><span class="hl-2">=></span><span class="hl-1"> </span><span class="hl-5">e</span><span class="hl-1">.</span><span class="hl-0">stopImmediatePropagation</span><span class="hl-1">());</span><br/><span class="hl-1"> </span><span class="hl-5">disposable</span><span class="hl-1"> = </span><span class="hl-0">addAbortListener</span><span class="hl-1">(</span><span class="hl-5">signal</span><span class="hl-1">, (</span><span class="hl-5">e</span><span class="hl-1">) </span><span class="hl-2">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-6">// Do something when signal is aborted.</span><br/><span class="hl-1"> });</span><br/><span class="hl-1"> } </span><span class="hl-4">finally</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">disposable</span><span class="hl-1">?.[</span><span class="hl-5">Symbol</span><span class="hl-1">.</span><span class="hl-5">dispose</span><span class="hl-1">]();</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
</div><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">signal</span>: <span class="tsd-signature-type">AbortSignal</span></span></li><li><span><span class="tsd-kind-parameter">resource</span>: <span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">event</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">Event</span><span class="tsd-signature-symbol">)</span> <span class="tsd-signature-symbol">=></span> <span class="tsd-signature-type">void</span></span></li></ul></div><h4 class="tsd-returns-title">Returns <a href="../interfaces/backend_script_entrypoint._internal_.Disposable.html" class="tsd-signature-type tsd-kind-interface">Disposable</a></h4><p>Disposable that removes the <code>abort</code> listener.</p>
|
||
<div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-20">Since<a href="#since-20" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v20.5.0</p>
|
||
</div></div><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/events.d.ts:437</li></ul></aside></div></li></ul></section><section class="tsd-panel tsd-member tsd-is-external"><h3 class="tsd-anchor-link" id="geteventlisteners"><code class="tsd-tag">Static</code><span>get<wbr/>Event<wbr/>Listeners</span><a href="#geteventlisteners" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-external"><li class="tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="geteventlisteners-1"><span class="tsd-kind-call-signature">getEventListeners</span><span class="tsd-signature-symbol">(</span><br/> <span class="tsd-kind-parameter">emitter</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">EventTarget</span> <span class="tsd-signature-symbol">|</span> <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html" class="tsd-signature-type tsd-kind-interface">EventEmitter</a><span class="tsd-signature-symbol"><</span><a href="../types/backend_script_entrypoint._internal_.DefaultEventMap.html" class="tsd-signature-type tsd-kind-type-alias">DefaultEventMap</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">,</span><br/> <span class="tsd-kind-parameter">name</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><br/><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><a href="#geteventlisteners-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><p>Returns a copy of the array of listeners for the event named <code>eventName</code>.</p>
|
||
<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="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">getEventListeners</span><span class="hl-1">, </span><span class="hl-5">EventEmitter</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><br/><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">ee</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><span class="hl-1"> </span><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-0">listener</span><span class="hl-1"> = () </span><span class="hl-2">=></span><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'Events are fun'</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">, </span><span class="hl-5">listener</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-0">getEventListeners</span><span class="hl-1">(</span><span class="hl-5">ee</span><span class="hl-1">, </span><span class="hl-3">'foo'</span><span class="hl-1">)); </span><span class="hl-6">// [ [Function: listener] ]</span><br/><span class="hl-1">}</span><br/><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">et</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventTarget</span><span class="hl-1">();</span><br/><span class="hl-1"> </span><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-0">listener</span><span class="hl-1"> = () </span><span class="hl-2">=></span><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'Events are fun'</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-5">et</span><span class="hl-1">.</span><span class="hl-0">addEventListener</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">, </span><span class="hl-5">listener</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-0">getEventListeners</span><span class="hl-1">(</span><span class="hl-5">et</span><span class="hl-1">, </span><span class="hl-3">'foo'</span><span class="hl-1">)); </span><span class="hl-6">// [ [Function: listener] ]</span><br/><span class="hl-1">}</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
</div><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">emitter</span>: <span class="tsd-signature-type">EventTarget</span> <span class="tsd-signature-symbol">|</span> <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html" class="tsd-signature-type tsd-kind-interface">EventEmitter</a><span class="tsd-signature-symbol"><</span><a href="../types/backend_script_entrypoint._internal_.DefaultEventMap.html" class="tsd-signature-type tsd-kind-type-alias">DefaultEventMap</a><span class="tsd-signature-symbol">></span></span></li><li><span><span class="tsd-kind-parameter">name</span>: <span class="tsd-signature-type">string</span> <span class="tsd-signature-symbol">|</span> <span class="tsd-signature-type">symbol</span></span></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Function</span><span class="tsd-signature-symbol">[]</span></h4><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-21">Since<a href="#since-21" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v15.2.0, v14.17.0</p>
|
||
</div></div><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/events.d.ts:358</li></ul></aside></div></li></ul></section><section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><h3 class="tsd-anchor-link" id="getmaxlisteners-2"><code class="tsd-tag">Static</code><span>get<wbr/>Max<wbr/>Listeners</span><a href="#getmaxlisteners-2" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-inherited tsd-is-external"><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="getmaxlisteners-3"><span class="tsd-kind-call-signature">getMaxListeners</span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">emitter</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">EventTarget</span> <span class="tsd-signature-symbol">|</span> <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html" class="tsd-signature-type tsd-kind-interface">EventEmitter</a><span class="tsd-signature-symbol"><</span><a href="../types/backend_script_entrypoint._internal_.DefaultEventMap.html" class="tsd-signature-type tsd-kind-type-alias">DefaultEventMap</a><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><a href="#getmaxlisteners-3" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><p>Returns the currently set max amount of listeners.</p>
|
||
<p>For <code>EventEmitter</code>s this behaves exactly the same as calling <code>.getMaxListeners</code> on
|
||
the emitter.</p>
|
||
<p>For <code>EventTarget</code>s this is the only way to get the max event listeners for the
|
||
event target. If the number of event handlers on a single EventTarget exceeds
|
||
the max set, the EventTarget will print a warning.</p>
|
||
<pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">getMaxListeners</span><span class="hl-1">, </span><span class="hl-5">setMaxListeners</span><span class="hl-1">, </span><span class="hl-5">EventEmitter</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><br/><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">ee</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-0">getMaxListeners</span><span class="hl-1">(</span><span class="hl-5">ee</span><span class="hl-1">)); </span><span class="hl-6">// 10</span><br/><span class="hl-1"> </span><span class="hl-0">setMaxListeners</span><span class="hl-1">(</span><span class="hl-9">11</span><span class="hl-1">, </span><span class="hl-5">ee</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-0">getMaxListeners</span><span class="hl-1">(</span><span class="hl-5">ee</span><span class="hl-1">)); </span><span class="hl-6">// 11</span><br/><span class="hl-1">}</span><br/><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">et</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventTarget</span><span class="hl-1">();</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-0">getMaxListeners</span><span class="hl-1">(</span><span class="hl-5">et</span><span class="hl-1">)); </span><span class="hl-6">// 10</span><br/><span class="hl-1"> </span><span class="hl-0">setMaxListeners</span><span class="hl-1">(</span><span class="hl-9">11</span><span class="hl-1">, </span><span class="hl-5">et</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-0">getMaxListeners</span><span class="hl-1">(</span><span class="hl-5">et</span><span class="hl-1">)); </span><span class="hl-6">// 11</span><br/><span class="hl-1">}</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
</div><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">emitter</span>: <span class="tsd-signature-type">EventTarget</span> <span class="tsd-signature-symbol">|</span> <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html" class="tsd-signature-type tsd-kind-interface">EventEmitter</a><span class="tsd-signature-symbol"><</span><a href="../types/backend_script_entrypoint._internal_.DefaultEventMap.html" class="tsd-signature-type tsd-kind-type-alias">DefaultEventMap</a><span class="tsd-signature-symbol">></span></span></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">number</span></h4><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-22">Since<a href="#since-22" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v19.9.0</p>
|
||
</div></div><aside class="tsd-sources"><p>Inherited from NodeJS.EventEmitter.getMaxListeners</p><ul><li>Defined in node_modules/@types/node/events.d.ts:387</li></ul></aside></div></li></ul></section><section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><h3 class="tsd-anchor-link" id="listenercount-2"><code class="tsd-tag">Static</code><span class="deprecated">listener<wbr/>Count</span><a href="#listenercount-2" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-inherited tsd-is-external"><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="listenercount-3"><span class="tsd-kind-call-signature">listenerCount</span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">emitter</span><span class="tsd-signature-symbol">:</span> <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html" class="tsd-signature-type tsd-kind-interface">EventEmitter</a><span class="tsd-signature-symbol">,</span> <span class="tsd-kind-parameter">eventName</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> <span class="tsd-signature-type">number</span><a href="#listenercount-3" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><p>A class method that returns the number of listeners for the given <code>eventName</code> registered on the given <code>emitter</code>.</p>
|
||
<pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">EventEmitter</span><span class="hl-1">, </span><span class="hl-5">listenerCount</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">myEmitter</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><span class="hl-5">myEmitter</span><span class="hl-1">.</span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-3">'event'</span><span class="hl-1">, () </span><span class="hl-2">=></span><span class="hl-1"> {});</span><br/><span class="hl-5">myEmitter</span><span class="hl-1">.</span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-3">'event'</span><span class="hl-1">, () </span><span class="hl-2">=></span><span class="hl-1"> {});</span><br/><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-0">listenerCount</span><span class="hl-1">(</span><span class="hl-5">myEmitter</span><span class="hl-1">, </span><span class="hl-3">'event'</span><span class="hl-1">));</span><br/><span class="hl-6">// Prints: 2</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
</div><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">emitter</span>: <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html" class="tsd-signature-type tsd-kind-interface">EventEmitter</a></span><div class="tsd-comment tsd-typography"><p>The emitter to query</p>
|
||
</div><div class="tsd-comment tsd-typography"></div></li><li><span><span class="tsd-kind-parameter">eventName</span>: <span class="tsd-signature-type">string</span> <span class="tsd-signature-symbol">|</span> <span class="tsd-signature-type">symbol</span></span><div class="tsd-comment tsd-typography"><p>The event name</p>
|
||
</div><div class="tsd-comment tsd-typography"></div></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">number</span></h4><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-23">Since<a href="#since-23" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v0.9.12</p>
|
||
</div><div class="tsd-tag-deprecated"><h4 class="tsd-anchor-link" id="deprecated">Deprecated<a href="#deprecated" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>Since v3.2.0 - Use <code>listenerCount</code> instead.</p>
|
||
</div></div><aside class="tsd-sources"><p>Inherited from NodeJS.EventEmitter.listenerCount</p><ul><li>Defined in node_modules/@types/node/events.d.ts:330</li></ul></aside></div></li></ul></section><section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><h3 class="tsd-anchor-link" id="on-2"><code class="tsd-tag">Static</code><span>on</span><a href="#on-2" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-inherited tsd-is-external"><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="on-3"><span class="tsd-kind-call-signature">on</span><span class="tsd-signature-symbol">(</span><br/> <span class="tsd-kind-parameter">emitter</span><span class="tsd-signature-symbol">:</span> <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html" class="tsd-signature-type tsd-kind-interface">EventEmitter</a><span class="tsd-signature-symbol">,</span><br/> <span class="tsd-kind-parameter">eventName</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><br/> <span class="tsd-kind-parameter">options</span><span class="tsd-signature-symbol">?:</span> <a href="../interfaces/backend_script_entrypoint._internal_.StaticEventEmitterIteratorOptions.html" class="tsd-signature-type tsd-kind-interface">StaticEventEmitterIteratorOptions</a><span class="tsd-signature-symbol">,</span><br/><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">AsyncIterator</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><a href="#on-3" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">on</span><span class="hl-1">, </span><span class="hl-5">EventEmitter</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><span class="hl-4">import</span><span class="hl-1"> </span><span class="hl-5">process</span><span class="hl-1"> </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:process'</span><span class="hl-1">;</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">ee</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><br/><span class="hl-6">// Emit later on</span><br/><span class="hl-5">process</span><span class="hl-1">.</span><span class="hl-0">nextTick</span><span class="hl-1">(() </span><span class="hl-2">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">, </span><span class="hl-3">'bar'</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">, </span><span class="hl-9">42</span><span class="hl-1">);</span><br/><span class="hl-1">});</span><br/><br/><span class="hl-4">for</span><span class="hl-1"> </span><span class="hl-4">await</span><span class="hl-1"> (</span><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">event</span><span class="hl-1"> </span><span class="hl-2">of</span><span class="hl-1"> </span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-5">ee</span><span class="hl-1">, </span><span class="hl-3">'foo'</span><span class="hl-1">)) {</span><br/><span class="hl-1"> </span><span class="hl-6">// The execution of this inner block is synchronous and it</span><br/><span class="hl-1"> </span><span class="hl-6">// processes one event at a time (even with await). Do not use</span><br/><span class="hl-1"> </span><span class="hl-6">// if concurrent execution is required.</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-5">event</span><span class="hl-1">); </span><span class="hl-6">// prints ['bar'] [42]</span><br/><span class="hl-1">}</span><br/><span class="hl-6">// Unreachable here</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
<p>Returns an <code>AsyncIterator</code> that iterates <code>eventName</code> events. It will throw
|
||
if the <code>EventEmitter</code> emits <code>'error'</code>. It removes all listeners when
|
||
exiting the loop. The <code>value</code> returned by each iteration is an array
|
||
composed of the emitted event arguments.</p>
|
||
<p>An <code>AbortSignal</code> can be used to cancel waiting on events:</p>
|
||
<pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">on</span><span class="hl-1">, </span><span class="hl-5">EventEmitter</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><span class="hl-4">import</span><span class="hl-1"> </span><span class="hl-5">process</span><span class="hl-1"> </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:process'</span><span class="hl-1">;</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">ac</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">AbortController</span><span class="hl-1">();</span><br/><br/><span class="hl-1">(</span><span class="hl-2">async</span><span class="hl-1"> () </span><span class="hl-2">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">ee</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><br/><span class="hl-1"> </span><span class="hl-6">// Emit later on</span><br/><span class="hl-1"> </span><span class="hl-5">process</span><span class="hl-1">.</span><span class="hl-0">nextTick</span><span class="hl-1">(() </span><span class="hl-2">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">, </span><span class="hl-3">'bar'</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">, </span><span class="hl-9">42</span><span class="hl-1">);</span><br/><span class="hl-1"> });</span><br/><br/><span class="hl-1"> </span><span class="hl-4">for</span><span class="hl-1"> </span><span class="hl-4">await</span><span class="hl-1"> (</span><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">event</span><span class="hl-1"> </span><span class="hl-2">of</span><span class="hl-1"> </span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-5">ee</span><span class="hl-1">, </span><span class="hl-3">'foo'</span><span class="hl-1">, { </span><span class="hl-5">signal:</span><span class="hl-1"> </span><span class="hl-5">ac</span><span class="hl-1">.</span><span class="hl-5">signal</span><span class="hl-1"> })) {</span><br/><span class="hl-1"> </span><span class="hl-6">// The execution of this inner block is synchronous and it</span><br/><span class="hl-1"> </span><span class="hl-6">// processes one event at a time (even with await). Do not use</span><br/><span class="hl-1"> </span><span class="hl-6">// if concurrent execution is required.</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-5">event</span><span class="hl-1">); </span><span class="hl-6">// prints ['bar'] [42]</span><br/><span class="hl-1"> }</span><br/><span class="hl-1"> </span><span class="hl-6">// Unreachable here</span><br/><span class="hl-1">})();</span><br/><br/><span class="hl-5">process</span><span class="hl-1">.</span><span class="hl-0">nextTick</span><span class="hl-1">(() </span><span class="hl-2">=></span><span class="hl-1"> </span><span class="hl-5">ac</span><span class="hl-1">.</span><span class="hl-0">abort</span><span class="hl-1">());</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
<p>Use the <code>close</code> option to specify an array of event names that will end the iteration:</p>
|
||
<pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">on</span><span class="hl-1">, </span><span class="hl-5">EventEmitter</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><span class="hl-4">import</span><span class="hl-1"> </span><span class="hl-5">process</span><span class="hl-1"> </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:process'</span><span class="hl-1">;</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">ee</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><br/><span class="hl-6">// Emit later on</span><br/><span class="hl-5">process</span><span class="hl-1">.</span><span class="hl-0">nextTick</span><span class="hl-1">(() </span><span class="hl-2">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">, </span><span class="hl-3">'bar'</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">, </span><span class="hl-9">42</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'close'</span><span class="hl-1">);</span><br/><span class="hl-1">});</span><br/><br/><span class="hl-4">for</span><span class="hl-1"> </span><span class="hl-4">await</span><span class="hl-1"> (</span><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">event</span><span class="hl-1"> </span><span class="hl-2">of</span><span class="hl-1"> </span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-5">ee</span><span class="hl-1">, </span><span class="hl-3">'foo'</span><span class="hl-1">, { </span><span class="hl-5">close:</span><span class="hl-1"> [</span><span class="hl-3">'close'</span><span class="hl-1">] })) {</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-5">event</span><span class="hl-1">); </span><span class="hl-6">// prints ['bar'] [42]</span><br/><span class="hl-1">}</span><br/><span class="hl-6">// the loop will exit after 'close' is emitted</span><br/><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'done'</span><span class="hl-1">); </span><span class="hl-6">// prints 'done'</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
</div><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">emitter</span>: <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html" class="tsd-signature-type tsd-kind-interface">EventEmitter</a></span></li><li><span><span class="tsd-kind-parameter">eventName</span>: <span class="tsd-signature-type">string</span> <span class="tsd-signature-symbol">|</span> <span class="tsd-signature-type">symbol</span></span></li><li><span><code class="tsd-tag">Optional</code><span class="tsd-kind-parameter">options</span>: <a href="../interfaces/backend_script_entrypoint._internal_.StaticEventEmitterIteratorOptions.html" class="tsd-signature-type tsd-kind-interface">StaticEventEmitterIteratorOptions</a></span></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">AsyncIterator</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><p>An <code>AsyncIterator</code> that iterates <code>eventName</code> events emitted by the <code>emitter</code></p>
|
||
<div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-24">Since<a href="#since-24" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v13.6.0, v12.16.0</p>
|
||
</div></div><aside class="tsd-sources"><p>Inherited from NodeJS.EventEmitter.on</p><ul><li>Defined in node_modules/@types/node/events.d.ts:303</li></ul></aside></div></li><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="on-4"><span class="tsd-kind-call-signature">on</span><span class="tsd-signature-symbol">(</span><br/> <span class="tsd-kind-parameter">emitter</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">EventTarget</span><span class="tsd-signature-symbol">,</span><br/> <span class="tsd-kind-parameter">eventName</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">,</span><br/> <span class="tsd-kind-parameter">options</span><span class="tsd-signature-symbol">?:</span> <a href="../interfaces/backend_script_entrypoint._internal_.StaticEventEmitterIteratorOptions.html" class="tsd-signature-type tsd-kind-interface">StaticEventEmitterIteratorOptions</a><span class="tsd-signature-symbol">,</span><br/><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">AsyncIterator</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><a href="#on-4" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">on</span><span class="hl-1">, </span><span class="hl-5">EventEmitter</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><span class="hl-4">import</span><span class="hl-1"> </span><span class="hl-5">process</span><span class="hl-1"> </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:process'</span><span class="hl-1">;</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">ee</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><br/><span class="hl-6">// Emit later on</span><br/><span class="hl-5">process</span><span class="hl-1">.</span><span class="hl-0">nextTick</span><span class="hl-1">(() </span><span class="hl-2">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">, </span><span class="hl-3">'bar'</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">, </span><span class="hl-9">42</span><span class="hl-1">);</span><br/><span class="hl-1">});</span><br/><br/><span class="hl-4">for</span><span class="hl-1"> </span><span class="hl-4">await</span><span class="hl-1"> (</span><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">event</span><span class="hl-1"> </span><span class="hl-2">of</span><span class="hl-1"> </span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-5">ee</span><span class="hl-1">, </span><span class="hl-3">'foo'</span><span class="hl-1">)) {</span><br/><span class="hl-1"> </span><span class="hl-6">// The execution of this inner block is synchronous and it</span><br/><span class="hl-1"> </span><span class="hl-6">// processes one event at a time (even with await). Do not use</span><br/><span class="hl-1"> </span><span class="hl-6">// if concurrent execution is required.</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-5">event</span><span class="hl-1">); </span><span class="hl-6">// prints ['bar'] [42]</span><br/><span class="hl-1">}</span><br/><span class="hl-6">// Unreachable here</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
<p>Returns an <code>AsyncIterator</code> that iterates <code>eventName</code> events. It will throw
|
||
if the <code>EventEmitter</code> emits <code>'error'</code>. It removes all listeners when
|
||
exiting the loop. The <code>value</code> returned by each iteration is an array
|
||
composed of the emitted event arguments.</p>
|
||
<p>An <code>AbortSignal</code> can be used to cancel waiting on events:</p>
|
||
<pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">on</span><span class="hl-1">, </span><span class="hl-5">EventEmitter</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><span class="hl-4">import</span><span class="hl-1"> </span><span class="hl-5">process</span><span class="hl-1"> </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:process'</span><span class="hl-1">;</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">ac</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">AbortController</span><span class="hl-1">();</span><br/><br/><span class="hl-1">(</span><span class="hl-2">async</span><span class="hl-1"> () </span><span class="hl-2">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">ee</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><br/><span class="hl-1"> </span><span class="hl-6">// Emit later on</span><br/><span class="hl-1"> </span><span class="hl-5">process</span><span class="hl-1">.</span><span class="hl-0">nextTick</span><span class="hl-1">(() </span><span class="hl-2">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">, </span><span class="hl-3">'bar'</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">, </span><span class="hl-9">42</span><span class="hl-1">);</span><br/><span class="hl-1"> });</span><br/><br/><span class="hl-1"> </span><span class="hl-4">for</span><span class="hl-1"> </span><span class="hl-4">await</span><span class="hl-1"> (</span><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">event</span><span class="hl-1"> </span><span class="hl-2">of</span><span class="hl-1"> </span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-5">ee</span><span class="hl-1">, </span><span class="hl-3">'foo'</span><span class="hl-1">, { </span><span class="hl-5">signal:</span><span class="hl-1"> </span><span class="hl-5">ac</span><span class="hl-1">.</span><span class="hl-5">signal</span><span class="hl-1"> })) {</span><br/><span class="hl-1"> </span><span class="hl-6">// The execution of this inner block is synchronous and it</span><br/><span class="hl-1"> </span><span class="hl-6">// processes one event at a time (even with await). Do not use</span><br/><span class="hl-1"> </span><span class="hl-6">// if concurrent execution is required.</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-5">event</span><span class="hl-1">); </span><span class="hl-6">// prints ['bar'] [42]</span><br/><span class="hl-1"> }</span><br/><span class="hl-1"> </span><span class="hl-6">// Unreachable here</span><br/><span class="hl-1">})();</span><br/><br/><span class="hl-5">process</span><span class="hl-1">.</span><span class="hl-0">nextTick</span><span class="hl-1">(() </span><span class="hl-2">=></span><span class="hl-1"> </span><span class="hl-5">ac</span><span class="hl-1">.</span><span class="hl-0">abort</span><span class="hl-1">());</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
<p>Use the <code>close</code> option to specify an array of event names that will end the iteration:</p>
|
||
<pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">on</span><span class="hl-1">, </span><span class="hl-5">EventEmitter</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><span class="hl-4">import</span><span class="hl-1"> </span><span class="hl-5">process</span><span class="hl-1"> </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:process'</span><span class="hl-1">;</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">ee</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><br/><span class="hl-6">// Emit later on</span><br/><span class="hl-5">process</span><span class="hl-1">.</span><span class="hl-0">nextTick</span><span class="hl-1">(() </span><span class="hl-2">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">, </span><span class="hl-3">'bar'</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">, </span><span class="hl-9">42</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'close'</span><span class="hl-1">);</span><br/><span class="hl-1">});</span><br/><br/><span class="hl-4">for</span><span class="hl-1"> </span><span class="hl-4">await</span><span class="hl-1"> (</span><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">event</span><span class="hl-1"> </span><span class="hl-2">of</span><span class="hl-1"> </span><span class="hl-0">on</span><span class="hl-1">(</span><span class="hl-5">ee</span><span class="hl-1">, </span><span class="hl-3">'foo'</span><span class="hl-1">, { </span><span class="hl-5">close:</span><span class="hl-1"> [</span><span class="hl-3">'close'</span><span class="hl-1">] })) {</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-5">event</span><span class="hl-1">); </span><span class="hl-6">// prints ['bar'] [42]</span><br/><span class="hl-1">}</span><br/><span class="hl-6">// the loop will exit after 'close' is emitted</span><br/><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'done'</span><span class="hl-1">); </span><span class="hl-6">// prints 'done'</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
</div><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">emitter</span>: <span class="tsd-signature-type">EventTarget</span></span></li><li><span><span class="tsd-kind-parameter">eventName</span>: <span class="tsd-signature-type">string</span></span></li><li><span><code class="tsd-tag">Optional</code><span class="tsd-kind-parameter">options</span>: <a href="../interfaces/backend_script_entrypoint._internal_.StaticEventEmitterIteratorOptions.html" class="tsd-signature-type tsd-kind-interface">StaticEventEmitterIteratorOptions</a></span></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">AsyncIterator</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><p>An <code>AsyncIterator</code> that iterates <code>eventName</code> events emitted by the <code>emitter</code></p>
|
||
<div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-25">Since<a href="#since-25" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v13.6.0, v12.16.0</p>
|
||
</div></div><aside class="tsd-sources"><p>Inherited from NodeJS.EventEmitter.on</p><ul><li>Defined in node_modules/@types/node/events.d.ts:308</li></ul></aside></div></li></ul></section><section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><h3 class="tsd-anchor-link" id="once-2"><code class="tsd-tag">Static</code><span>once</span><a href="#once-2" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-inherited tsd-is-external"><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="once-3"><span class="tsd-kind-call-signature">once</span><span class="tsd-signature-symbol">(</span><br/> <span class="tsd-kind-parameter">emitter</span><span class="tsd-signature-symbol">:</span> <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html" class="tsd-signature-type tsd-kind-interface">EventEmitter</a><span class="tsd-signature-symbol">,</span><br/> <span class="tsd-kind-parameter">eventName</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><br/> <span class="tsd-kind-parameter">options</span><span class="tsd-signature-symbol">?:</span> <a href="../interfaces/backend_script_entrypoint._internal_.StaticEventEmitterOptions.html" class="tsd-signature-type tsd-kind-interface">StaticEventEmitterOptions</a><span class="tsd-signature-symbol">,</span><br/><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><a href="#once-3" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><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>
|
||
<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="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">once</span><span class="hl-1">, </span><span class="hl-5">EventEmitter</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><span class="hl-4">import</span><span class="hl-1"> </span><span class="hl-5">process</span><span class="hl-1"> </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:process'</span><span class="hl-1">;</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">ee</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><br/><span class="hl-5">process</span><span class="hl-1">.</span><span class="hl-0">nextTick</span><span class="hl-1">(() </span><span class="hl-2">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'myevent'</span><span class="hl-1">, </span><span class="hl-9">42</span><span class="hl-1">);</span><br/><span class="hl-1">});</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> [</span><span class="hl-7">value</span><span class="hl-1">] = </span><span class="hl-4">await</span><span class="hl-1"> </span><span class="hl-0">once</span><span class="hl-1">(</span><span class="hl-5">ee</span><span class="hl-1">, </span><span class="hl-3">'myevent'</span><span class="hl-1">);</span><br/><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-5">value</span><span class="hl-1">);</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">err</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">Error</span><span class="hl-1">(</span><span class="hl-3">'kaboom'</span><span class="hl-1">);</span><br/><span class="hl-5">process</span><span class="hl-1">.</span><span class="hl-0">nextTick</span><span class="hl-1">(() </span><span class="hl-2">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'error'</span><span class="hl-1">, </span><span class="hl-5">err</span><span class="hl-1">);</span><br/><span class="hl-1">});</span><br/><br/><span class="hl-4">try</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-4">await</span><span class="hl-1"> </span><span class="hl-0">once</span><span class="hl-1">(</span><span class="hl-5">ee</span><span class="hl-1">, </span><span class="hl-3">'myevent'</span><span class="hl-1">);</span><br/><span class="hl-1">} </span><span class="hl-4">catch</span><span class="hl-1"> (</span><span class="hl-5">err</span><span class="hl-1">) {</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">error</span><span class="hl-1">(</span><span class="hl-3">'error happened'</span><span class="hl-1">, </span><span class="hl-5">err</span><span class="hl-1">);</span><br/><span class="hl-1">}</span>
|
||
</code><button type="button">Copy</button></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="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">EventEmitter</span><span class="hl-1">, </span><span class="hl-5">once</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">ee</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><br/><span class="hl-0">once</span><span class="hl-1">(</span><span class="hl-5">ee</span><span class="hl-1">, </span><span class="hl-3">'error'</span><span class="hl-1">)</span><br/><span class="hl-1"> .</span><span class="hl-0">then</span><span class="hl-1">(([</span><span class="hl-5">err</span><span class="hl-1">]) </span><span class="hl-2">=></span><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'ok'</span><span class="hl-1">, </span><span class="hl-5">err</span><span class="hl-1">.</span><span class="hl-5">message</span><span class="hl-1">))</span><br/><span class="hl-1"> .</span><span class="hl-0">catch</span><span class="hl-1">((</span><span class="hl-5">err</span><span class="hl-1">) </span><span class="hl-2">=></span><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">error</span><span class="hl-1">(</span><span class="hl-3">'error'</span><span class="hl-1">, </span><span class="hl-5">err</span><span class="hl-1">.</span><span class="hl-5">message</span><span class="hl-1">));</span><br/><br/><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'error'</span><span class="hl-1">, </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">Error</span><span class="hl-1">(</span><span class="hl-3">'boom'</span><span class="hl-1">));</span><br/><br/><span class="hl-6">// Prints: ok boom</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
<p>An <code>AbortSignal</code> can be used to cancel waiting for the event:</p>
|
||
<pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">EventEmitter</span><span class="hl-1">, </span><span class="hl-5">once</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">ee</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">ac</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">AbortController</span><span class="hl-1">();</span><br/><br/><span class="hl-2">async</span><span class="hl-1"> </span><span class="hl-2">function</span><span class="hl-1"> </span><span class="hl-0">foo</span><span class="hl-1">(</span><span class="hl-5">emitter</span><span class="hl-1">, </span><span class="hl-5">event</span><span class="hl-1">, </span><span class="hl-5">signal</span><span class="hl-1">) {</span><br/><span class="hl-1"> </span><span class="hl-4">try</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-4">await</span><span class="hl-1"> </span><span class="hl-0">once</span><span class="hl-1">(</span><span class="hl-5">emitter</span><span class="hl-1">, </span><span class="hl-5">event</span><span class="hl-1">, { </span><span class="hl-5">signal</span><span class="hl-1"> });</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'event emitted!'</span><span class="hl-1">);</span><br/><span class="hl-1"> } </span><span class="hl-4">catch</span><span class="hl-1"> (</span><span class="hl-5">error</span><span class="hl-1">) {</span><br/><span class="hl-1"> </span><span class="hl-4">if</span><span class="hl-1"> (</span><span class="hl-5">error</span><span class="hl-1">.</span><span class="hl-5">name</span><span class="hl-1"> === </span><span class="hl-3">'AbortError'</span><span class="hl-1">) {</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">error</span><span class="hl-1">(</span><span class="hl-3">'Waiting for the event was canceled!'</span><span class="hl-1">);</span><br/><span class="hl-1"> } </span><span class="hl-4">else</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">error</span><span class="hl-1">(</span><span class="hl-3">'There was an error'</span><span class="hl-1">, </span><span class="hl-5">error</span><span class="hl-1">.</span><span class="hl-5">message</span><span class="hl-1">);</span><br/><span class="hl-1"> }</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span><br/><br/><span class="hl-0">foo</span><span class="hl-1">(</span><span class="hl-5">ee</span><span class="hl-1">, </span><span class="hl-3">'foo'</span><span class="hl-1">, </span><span class="hl-5">ac</span><span class="hl-1">.</span><span class="hl-5">signal</span><span class="hl-1">);</span><br/><span class="hl-5">ac</span><span class="hl-1">.</span><span class="hl-0">abort</span><span class="hl-1">(); </span><span class="hl-6">// Abort waiting for the event</span><br/><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">); </span><span class="hl-6">// Prints: Waiting for the event was canceled!</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
</div><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">emitter</span>: <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html" class="tsd-signature-type tsd-kind-interface">EventEmitter</a></span></li><li><span><span class="tsd-kind-parameter">eventName</span>: <span class="tsd-signature-type">string</span> <span class="tsd-signature-symbol">|</span> <span class="tsd-signature-type">symbol</span></span></li><li><span><code class="tsd-tag">Optional</code><span class="tsd-kind-parameter">options</span>: <a href="../interfaces/backend_script_entrypoint._internal_.StaticEventEmitterOptions.html" class="tsd-signature-type tsd-kind-interface">StaticEventEmitterOptions</a></span></li></ul></div><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><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-26">Since<a href="#since-26" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v11.13.0, v10.16.0</p>
|
||
</div></div><aside class="tsd-sources"><p>Inherited from NodeJS.EventEmitter.once</p><ul><li>Defined in node_modules/@types/node/events.d.ts:217</li></ul></aside></div></li><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="once-4"><span class="tsd-kind-call-signature">once</span><span class="tsd-signature-symbol">(</span><br/> <span class="tsd-kind-parameter">emitter</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">EventTarget</span><span class="tsd-signature-symbol">,</span><br/> <span class="tsd-kind-parameter">eventName</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">,</span><br/> <span class="tsd-kind-parameter">options</span><span class="tsd-signature-symbol">?:</span> <a href="../interfaces/backend_script_entrypoint._internal_.StaticEventEmitterOptions.html" class="tsd-signature-type tsd-kind-interface">StaticEventEmitterOptions</a><span class="tsd-signature-symbol">,</span><br/><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><a href="#once-4" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><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>
|
||
<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="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">once</span><span class="hl-1">, </span><span class="hl-5">EventEmitter</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><span class="hl-4">import</span><span class="hl-1"> </span><span class="hl-5">process</span><span class="hl-1"> </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:process'</span><span class="hl-1">;</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">ee</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><br/><span class="hl-5">process</span><span class="hl-1">.</span><span class="hl-0">nextTick</span><span class="hl-1">(() </span><span class="hl-2">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'myevent'</span><span class="hl-1">, </span><span class="hl-9">42</span><span class="hl-1">);</span><br/><span class="hl-1">});</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> [</span><span class="hl-7">value</span><span class="hl-1">] = </span><span class="hl-4">await</span><span class="hl-1"> </span><span class="hl-0">once</span><span class="hl-1">(</span><span class="hl-5">ee</span><span class="hl-1">, </span><span class="hl-3">'myevent'</span><span class="hl-1">);</span><br/><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-5">value</span><span class="hl-1">);</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">err</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">Error</span><span class="hl-1">(</span><span class="hl-3">'kaboom'</span><span class="hl-1">);</span><br/><span class="hl-5">process</span><span class="hl-1">.</span><span class="hl-0">nextTick</span><span class="hl-1">(() </span><span class="hl-2">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'error'</span><span class="hl-1">, </span><span class="hl-5">err</span><span class="hl-1">);</span><br/><span class="hl-1">});</span><br/><br/><span class="hl-4">try</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-4">await</span><span class="hl-1"> </span><span class="hl-0">once</span><span class="hl-1">(</span><span class="hl-5">ee</span><span class="hl-1">, </span><span class="hl-3">'myevent'</span><span class="hl-1">);</span><br/><span class="hl-1">} </span><span class="hl-4">catch</span><span class="hl-1"> (</span><span class="hl-5">err</span><span class="hl-1">) {</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">error</span><span class="hl-1">(</span><span class="hl-3">'error happened'</span><span class="hl-1">, </span><span class="hl-5">err</span><span class="hl-1">);</span><br/><span class="hl-1">}</span>
|
||
</code><button type="button">Copy</button></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="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">EventEmitter</span><span class="hl-1">, </span><span class="hl-5">once</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">ee</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><br/><span class="hl-0">once</span><span class="hl-1">(</span><span class="hl-5">ee</span><span class="hl-1">, </span><span class="hl-3">'error'</span><span class="hl-1">)</span><br/><span class="hl-1"> .</span><span class="hl-0">then</span><span class="hl-1">(([</span><span class="hl-5">err</span><span class="hl-1">]) </span><span class="hl-2">=></span><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'ok'</span><span class="hl-1">, </span><span class="hl-5">err</span><span class="hl-1">.</span><span class="hl-5">message</span><span class="hl-1">))</span><br/><span class="hl-1"> .</span><span class="hl-0">catch</span><span class="hl-1">((</span><span class="hl-5">err</span><span class="hl-1">) </span><span class="hl-2">=></span><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">error</span><span class="hl-1">(</span><span class="hl-3">'error'</span><span class="hl-1">, </span><span class="hl-5">err</span><span class="hl-1">.</span><span class="hl-5">message</span><span class="hl-1">));</span><br/><br/><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'error'</span><span class="hl-1">, </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">Error</span><span class="hl-1">(</span><span class="hl-3">'boom'</span><span class="hl-1">));</span><br/><br/><span class="hl-6">// Prints: ok boom</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
<p>An <code>AbortSignal</code> can be used to cancel waiting for the event:</p>
|
||
<pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">EventEmitter</span><span class="hl-1">, </span><span class="hl-5">once</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">ee</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">ac</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">AbortController</span><span class="hl-1">();</span><br/><br/><span class="hl-2">async</span><span class="hl-1"> </span><span class="hl-2">function</span><span class="hl-1"> </span><span class="hl-0">foo</span><span class="hl-1">(</span><span class="hl-5">emitter</span><span class="hl-1">, </span><span class="hl-5">event</span><span class="hl-1">, </span><span class="hl-5">signal</span><span class="hl-1">) {</span><br/><span class="hl-1"> </span><span class="hl-4">try</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-4">await</span><span class="hl-1"> </span><span class="hl-0">once</span><span class="hl-1">(</span><span class="hl-5">emitter</span><span class="hl-1">, </span><span class="hl-5">event</span><span class="hl-1">, { </span><span class="hl-5">signal</span><span class="hl-1"> });</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-3">'event emitted!'</span><span class="hl-1">);</span><br/><span class="hl-1"> } </span><span class="hl-4">catch</span><span class="hl-1"> (</span><span class="hl-5">error</span><span class="hl-1">) {</span><br/><span class="hl-1"> </span><span class="hl-4">if</span><span class="hl-1"> (</span><span class="hl-5">error</span><span class="hl-1">.</span><span class="hl-5">name</span><span class="hl-1"> === </span><span class="hl-3">'AbortError'</span><span class="hl-1">) {</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">error</span><span class="hl-1">(</span><span class="hl-3">'Waiting for the event was canceled!'</span><span class="hl-1">);</span><br/><span class="hl-1"> } </span><span class="hl-4">else</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">console</span><span class="hl-1">.</span><span class="hl-0">error</span><span class="hl-1">(</span><span class="hl-3">'There was an error'</span><span class="hl-1">, </span><span class="hl-5">error</span><span class="hl-1">.</span><span class="hl-5">message</span><span class="hl-1">);</span><br/><span class="hl-1"> }</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span><br/><br/><span class="hl-0">foo</span><span class="hl-1">(</span><span class="hl-5">ee</span><span class="hl-1">, </span><span class="hl-3">'foo'</span><span class="hl-1">, </span><span class="hl-5">ac</span><span class="hl-1">.</span><span class="hl-5">signal</span><span class="hl-1">);</span><br/><span class="hl-5">ac</span><span class="hl-1">.</span><span class="hl-0">abort</span><span class="hl-1">(); </span><span class="hl-6">// Abort waiting for the event</span><br/><span class="hl-5">ee</span><span class="hl-1">.</span><span class="hl-0">emit</span><span class="hl-1">(</span><span class="hl-3">'foo'</span><span class="hl-1">); </span><span class="hl-6">// Prints: Waiting for the event was canceled!</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
</div><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">emitter</span>: <span class="tsd-signature-type">EventTarget</span></span></li><li><span><span class="tsd-kind-parameter">eventName</span>: <span class="tsd-signature-type">string</span></span></li><li><span><code class="tsd-tag">Optional</code><span class="tsd-kind-parameter">options</span>: <a href="../interfaces/backend_script_entrypoint._internal_.StaticEventEmitterOptions.html" class="tsd-signature-type tsd-kind-interface">StaticEventEmitterOptions</a></span></li></ul></div><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><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-27">Since<a href="#since-27" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v11.13.0, v10.16.0</p>
|
||
</div></div><aside class="tsd-sources"><p>Inherited from NodeJS.EventEmitter.once</p><ul><li>Defined in node_modules/@types/node/events.d.ts:222</li></ul></aside></div></li></ul></section><section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><h3 class="tsd-anchor-link" id="setmaxlisteners-2"><code class="tsd-tag">Static</code><span>set<wbr/>Max<wbr/>Listeners</span><a href="#setmaxlisteners-2" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures tsd-is-inherited tsd-is-external"><li class="tsd-is-inherited tsd-is-external"><div class="tsd-signature tsd-anchor-link" id="setmaxlisteners-3"><span class="tsd-kind-call-signature">setMaxListeners</span><span class="tsd-signature-symbol">(</span><br/> <span class="tsd-kind-parameter">n</span><span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">,</span><br/> <span class="tsd-signature-symbol">...</span><span class="tsd-kind-parameter">eventTargets</span><span class="tsd-signature-symbol">:</span> (<span class="tsd-signature-type">EventTarget</span> <span class="tsd-signature-symbol">|</span> <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html" class="tsd-signature-type tsd-kind-interface">EventEmitter</a><span class="tsd-signature-symbol"><</span><a href="../types/backend_script_entrypoint._internal_.DefaultEventMap.html" class="tsd-signature-type tsd-kind-type-alias">DefaultEventMap</a><span class="tsd-signature-symbol">></span>)<span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">,</span><br/><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">void</span><a href="#setmaxlisteners-3" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">setMaxListeners</span><span class="hl-1">, </span><span class="hl-5">EventEmitter</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-3">'node:events'</span><span class="hl-1">;</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">target</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventTarget</span><span class="hl-1">();</span><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-7">emitter</span><span class="hl-1"> = </span><span class="hl-2">new</span><span class="hl-1"> </span><span class="hl-0">EventEmitter</span><span class="hl-1">();</span><br/><br/><span class="hl-0">setMaxListeners</span><span class="hl-1">(</span><span class="hl-9">5</span><span class="hl-1">, </span><span class="hl-5">target</span><span class="hl-1">, </span><span class="hl-5">emitter</span><span class="hl-1">);</span>
|
||
</code><button type="button">Copy</button></pre>
|
||
|
||
</div><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><code class="tsd-tag">Optional</code><span class="tsd-kind-parameter">n</span>: <span class="tsd-signature-type">number</span></span><div class="tsd-comment tsd-typography"><p>A non-negative number. The maximum number of listeners per <code>EventTarget</code> event.</p>
|
||
</div><div class="tsd-comment tsd-typography"></div></li><li><span><span class="tsd-signature-symbol">...</span><span class="tsd-kind-parameter">eventTargets</span>: (<span class="tsd-signature-type">EventTarget</span> <span class="tsd-signature-symbol">|</span> <a href="../interfaces/backend_script_entrypoint._internal_.EventEmitter.html" class="tsd-signature-type tsd-kind-interface">EventEmitter</a><span class="tsd-signature-symbol"><</span><a href="../types/backend_script_entrypoint._internal_.DefaultEventMap.html" class="tsd-signature-type tsd-kind-type-alias">DefaultEventMap</a><span class="tsd-signature-symbol">></span>)<span class="tsd-signature-symbol">[]</span></span><div class="tsd-comment tsd-typography"><p>Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, <code>n</code> is set as the default max for all newly created {EventTarget} and {EventEmitter}
|
||
objects.</p>
|
||
</div><div class="tsd-comment tsd-typography"></div></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4><div class="tsd-comment tsd-typography"><div class="tsd-tag-since"><h4 class="tsd-anchor-link" id="since-28">Since<a href="#since-28" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>v15.4.0</p>
|
||
</div></div><aside class="tsd-sources"><p>Inherited from NodeJS.EventEmitter.setMaxListeners</p><ul><li>Defined in node_modules/@types/node/events.d.ts:402</li></ul></aside></div></li></ul></section></section></details></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h3>On This Page</h3></summary><div class="tsd-accordion-details"><details open class="tsd-accordion tsd-page-navigation-section"><summary class="tsd-accordion-summary" data-key="section-Constructors"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Constructors</summary><div><a href="#constructor" class="tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Constructor"><use href="../assets/icons.svg#icon-512"></use></svg><span>constructor</span></a></div></details><details open class="tsd-accordion tsd-page-navigation-section"><summary class="tsd-accordion-summary" data-key="section-Properties"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Properties</summary><div><a href="#capturerejections" class="tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Property"><use href="../assets/icons.svg#icon-1024"></use></svg><span>capture<wbr/>Rejections</span></a><a href="#capturerejectionsymbol" class="tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Property"><use href="../assets/icons.svg#icon-1024"></use></svg><span>capture<wbr/>Rejection<wbr/>Symbol</span></a><a href="#defaultmaxlisteners" class="tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Property"><use href="../assets/icons.svg#icon-1024"></use></svg><span>default<wbr/>Max<wbr/>Listeners</span></a><a href="#errormonitor" class="tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Property"><use href="../assets/icons.svg#icon-1024"></use></svg><span>error<wbr/>Monitor</span></a></div></details><details open class="tsd-accordion tsd-page-navigation-section"><summary class="tsd-accordion-summary" data-key="section-Methods"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Methods</summary><div><a href="#capturerejectionsymbol-1" class="tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>[capture<wbr/>Rejection<wbr/>Symbol]</span></a><a href="#addlistener" class="tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>add<wbr/>Listener</span></a><a href="#emit" class="tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>emit</span></a><a href="#eventnames" class="tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>event<wbr/>Names</span></a><a href="#getmaxlisteners" class="tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>get<wbr/>Max<wbr/>Listeners</span></a><a href="#listenercount" class="tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>listener<wbr/>Count</span></a><a href="#listeners" class="tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>listeners</span></a><a href="#off" class="tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>off</span></a><a href="#on" class="tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>on</span></a><a href="#once" class="tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>once</span></a><a href="#prependlistener" class="tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>prepend<wbr/>Listener</span></a><a href="#prependoncelistener" class="tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>prepend<wbr/>Once<wbr/>Listener</span></a><a href="#rawlisteners" class="tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>raw<wbr/>Listeners</span></a><a href="#removealllisteners" class="tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>remove<wbr/>All<wbr/>Listeners</span></a><a href="#removelistener" class="tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>remove<wbr/>Listener</span></a><a href="#setmaxlisteners" class="tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>set<wbr/>Max<wbr/>Listeners</span></a><a href="#addabortlistener" class="tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>add<wbr/>Abort<wbr/>Listener</span></a><a href="#geteventlisteners" class="tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>get<wbr/>Event<wbr/>Listeners</span></a><a href="#getmaxlisteners-2" class="tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>get<wbr/>Max<wbr/>Listeners</span></a><a href="#listenercount-2" class="tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>listener<wbr/>Count</span></a><a href="#on-2" class="tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>on</span></a><a href="#once-2" class="tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>once</span></a><a href="#setmaxlisteners-2" class="tsd-is-inherited tsd-is-external"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Method"><use href="../assets/icons.svg#icon-2048"></use></svg><span>set<wbr/>Max<wbr/>Listeners</span></a></div></details></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">trilium</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|