2022-01-18 22:24:49 +09:00
<!DOCTYPE html> < html class = "default" > < head > < meta charSet = "utf-8" / > < meta http-equiv = "x-ua-compatible" content = "IE=edge" / > < title > GPIOAccess | node-web-gpio< / title > < meta name = "description" content = "Documentation for node-web-gpio" / > < meta name = "viewport" content = "width=device-width, initial-scale=1" / > < link rel = "stylesheet" href = "../assets/style.css" / > < link rel = "stylesheet" href = "../assets/highlight.css" / > < script async src = "../assets/search.js" id = "search-script" > < / script > < / head > < body > < script > document . body . classList . add ( localStorage . getItem ( "tsd-theme" ) || "os" ) < / script > < header > < div class = "tsd-page-toolbar" > < div class = "container" > < div class = "table-wrap" > < div class = "table-cell" id = "tsd-search" data-base = ".." > < div class = "field" > < label for = "tsd-search-field" class = "tsd-widget search no-caption" > Search< / label > < input type = "text" id = "tsd-search-field" / > < / div > < ul class = "results" > < li class = "state loading" > Preparing search index...< / li > < li class = "state failure" > The search index is not available< / li > < / ul > < a href = "../index.html" class = "title" > node-web-gpio< / a > < / div > < div class = "table-cell" id = "tsd-widgets" > < div id = "tsd-filter" > < a href = "#" class = "tsd-widget options no-caption" data-toggle = "options" > Options< / a > < div class = "tsd-filter-group" > < div class = "tsd-select" id = "tsd-filter-visibility" > < span class = "tsd-select-label" > All< / span > < ul class = "tsd-select-list" > < li data-value = "public" > Public< / li > < li data-value = "protected" > Public/Protected< / li > < li data-value = "private" class = "selected" > All< / li > < / ul > < / div > < input type = "checkbox" id = "tsd-filter-inherited" checked / > < label class = "tsd-widget" for = "tsd-filter-inherited" > Inherited< / label > < input type = "checkbox" id = "tsd-filter-externals" checked / > < label class = "tsd-widget" for = "tsd-filter-externals" > Externals< / label > < / div > < / div > < a href = "#" class = "tsd-widget menu no-caption" data-toggle = "menu" > Menu< / a > < / div > < / div > < / div > < / div > < div class = "tsd-page-title" > < div class = "container" > < ul class = "tsd-breadcrumb" > < li > < a href = "../modules.html" > node-web-gpio< / a > < / li > < li > < a href = "GPIOAccess.html" > GPIOAccess< / a > < / li > < / ul > < h1 > Class GPIOAccess< / h1 > < / div > < / div > < / header > < div class = "container container-main" > < div class = "row" > < div class = "col-8 col-content" > < section class = "tsd-panel tsd-comment" > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > GPIO< / p >
2022-04-02 12:59:10 +09:00
< / div > < / div > < / section > < section class = "tsd-panel tsd-hierarchy" > < h3 > Hierarchy< / h3 > < ul class = "tsd-hierarchy" > < li > < span class = "tsd-signature-type" > EventEmitter< / span > < ul class = "tsd-hierarchy" > < li > < span class = "target" > GPIOAccess< / span > < / li > < / ul > < / li > < / ul > < / section > < section class = "tsd-panel-group tsd-index-group" > < h2 > Index< / h2 > < section class = "tsd-panel tsd-index-panel" > < div class = "tsd-index-content" > < section class = "tsd-index-section " > < h3 > Constructors< / h3 > < ul class = "tsd-index-list" > < li class = "tsd-kind-constructor tsd-parent-kind-class tsd-is-overwrite" > < a href = "GPIOAccess.html#constructor" class = "tsd-kind-icon" > constructor< / a > < / li > < / ul > < / section > < section class = "tsd-index-section " > < h3 > Properties< / h3 > < ul class = "tsd-index-list" > < li class = "tsd-kind-property tsd-parent-kind-class tsd-is-private" > < a href = "GPIOAccess.html#_ports" class = "tsd-kind-icon" > _ports< / a > < / li > < li class = "tsd-kind-property tsd-parent-kind-class" > < a href = "GPIOAccess.html#onchange" class = "tsd-kind-icon" > onchange< / a > < / li > < li class = "tsd-kind-property tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external" > < a href = "GPIOAccess.html#captureRejectionSymbol" class = "tsd-kind-icon" > capture< wbr / > Rejection< wbr / > Symbol< / a > < / li > < li class = "tsd-kind-property tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external" > < a href = "GPIOAccess.html#captureRejections" class = "tsd-kind-icon" > capture< wbr / > Rejections< / a > < / li > < li class = "tsd-kind-property tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external" > < a href = "GPIOAccess.html#defaultMaxListeners" class = "tsd-kind-icon" > default< wbr / > Max< wbr / > Listeners< / a > < / li > < li class = "tsd-kind-property tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external" > < a href = "GPIOAccess.html#errorMonitor" class = "tsd-kind-icon" > error< wbr / > Monitor< / a > < / li > < / ul > < / section > < section class = "tsd-index-section " > < h3 > Accessors< / h3 > < ul class = "tsd-index-list" > < li class = "tsd-kind-get-signature tsd-parent-kind-class" > < a href = "GPIOAccess.html#ports" class = "tsd-kind-icon" > ports< / a > < / li > < / ul > < / section > < section class = "tsd-index-section " > < h3 > Methods< / h3 > < ul class = "tsd-index-list" > < li class = "tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a href = "GPIOAccess.html#addListener" class = "tsd-kind-icon" > add< wbr / > Listener< / a > < / li > < li class = "tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a href = "GPIOAccess.html#emit" class = "tsd-kind-icon" > emit< / a > < / li > < li class = "tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a href = "GPIOAccess.html#eventNames" class = "tsd-kind-icon" > event< wbr / > Names< / a > < / li > < li class = "tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a href = "GPIOAccess.html#getMaxListeners" class = "tsd-kind-icon" > get< wbr / > Max< wbr / > Listeners< / a > < / li > < li class = "tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a href = "GPIOAccess.html#listenerCount" class = "tsd-kind-icon" > listener< wbr / > Count< / a > < / li > < li class = "tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a href = "GPIOAccess.html#listeners" class = "tsd-kind-icon" > listeners< / a > < / li > < li class = "tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a href = "GPIOAccess.html#off" class = "tsd-kind-icon" > off< / a > < / li > < li class = "tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a href = "GPIOAccess.html#on" class = "tsd-kind-icon" > on< / a > < / li > < li class = "tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a href = "GPIOAccess.html#once" class = "tsd-kind-icon" > once< / a > < / li > < li class = "tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a href = "GPIOAccess.html#prependListener" class = "tsd-kind-icon" > prepend< wbr / > Listener< / a > < / li > < li class = "tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a href = "GPIOAccess.html#prependOnceListener" class = "tsd-kind-icon" > prepend< wbr / > Once< wbr / > Listener< / a > < / li > < li class = "tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a href = "GPIOAccess.html#rawListeners" class = "tsd-kind-icon" > raw< wbr / > Listeners< / a > < / li > < l
2022-01-18 22:24:49 +09:00
< p > Creates an instance of GPIOAccess.< / p >
< / div > < / div > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > < span class = "tsd-flag ts-flagOptional" > Optional< / span > ports: < a href = "GPIOPortMap.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOPortMap< / a > < / h5 > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > ポート番号< / p >
2022-04-02 12:59:10 +09:00
< / div > < / div > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < a href = "GPIOAccess.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOAccess< / a > < / h4 > < / li > < / ul > < / section > < / section > < section class = "tsd-panel-group tsd-member-group " > < h2 > Properties< / h2 > < section class = "tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-private" > < a id = "_ports" class = "tsd-anchor" > < / a > < h3 > < span class = "tsd-flag ts-flagPrivate" > Private< / span > < span class = "tsd-flag ts-flagReadonly" > Readonly< / span > _ports< / h3 > < div class = "tsd-signature tsd-kind-icon" > _ports< span class = "tsd-signature-symbol" > :< / span > < a href = "GPIOPortMap.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOPortMap< / a > < / div > < aside class = "tsd-sources" > < ul > < li > Defined in < a href = "https://github.com/chirimen-oh/node-web-gpio/blob/61f53c0/index.ts#L73" > index.ts:73< / a > < / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
2022-01-18 22:24:49 +09:00
< p > ポート< / p >
2022-04-02 12:59:10 +09:00
< / div > < / div > < / section > < section class = "tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class" > < a id = "onchange" class = "tsd-anchor" > < / a > < h3 > onchange< / h3 > < div class = "tsd-signature tsd-kind-icon" > onchange< span class = "tsd-signature-symbol" > :< / span > < span class = "tsd-signature-type" > undefined< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > GPIOChangeEventHandler< / span > < / div > < aside class = "tsd-sources" > < ul > < li > Defined in < a href = "https://github.com/chirimen-oh/node-web-gpio/blob/61f53c0/index.ts#L75" > index.ts:75< / a > < / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
2022-01-18 22:24:49 +09:00
< p > GPIO チェンジイベントハンドラ< / p >
< / div > < / div > < / section > < section class = "tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external" > < a id = "captureRejectionSymbol" class = "tsd-anchor" > < / a > < h3 > < span class = "tsd-flag ts-flagStatic" > Static< / span > < span class = "tsd-flag ts-flagReadonly" > Readonly< / span > capture< wbr / > Rejection< wbr / > Symbol< / h3 > < div class = "tsd-signature tsd-kind-icon" > capture< wbr / > Rejection< wbr / > Symbol< span class = "tsd-signature-symbol" > :< / span > < span class = "tsd-signature-symbol" > typeof < / span > < a href = "GPIOAccess.html#captureRejectionSymbol" class = "tsd-signature-type" data-tsd-kind = "Property" > captureRejectionSymbol< / a > < / div > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.captureRejectionSymbol< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:273< / li > < / ul > < / aside > < / section > < section class = "tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external" > < a id = "captureRejections" class = "tsd-anchor" > < / a > < h3 > < span class = "tsd-flag ts-flagStatic" > Static< / span > capture< wbr / > Rejections< / h3 > < div class = "tsd-signature tsd-kind-icon" > capture< wbr / > Rejections< span class = "tsd-signature-symbol" > :< / span > < span class = "tsd-signature-type" > boolean< / span > < / div > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.captureRejections< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:278< / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > Sets or gets the default captureRejection value for all emitters.< / p >
< / div > < / div > < / section > < section class = "tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external" > < a id = "defaultMaxListeners" class = "tsd-anchor" > < / a > < h3 > < span class = "tsd-flag ts-flagStatic" > Static< / span > default< wbr / > Max< wbr / > Listeners< / h3 > < div class = "tsd-signature tsd-kind-icon" > default< wbr / > Max< wbr / > Listeners< span class = "tsd-signature-symbol" > :< / span > < span class = "tsd-signature-type" > number< / span > < / div > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.defaultMaxListeners< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:279< / li > < / ul > < / aside > < / section > < section class = "tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external" > < a id = "errorMonitor" class = "tsd-anchor" > < / a > < h3 > < span class = "tsd-flag ts-flagStatic" > Static< / span > < span class = "tsd-flag ts-flagReadonly" > Readonly< / span > error< wbr / > Monitor< / h3 > < div class = "tsd-signature tsd-kind-icon" > error< wbr / > Monitor< span class = "tsd-signature-symbol" > :< / span > < span class = "tsd-signature-symbol" > typeof < / span > < a href = "GPIOAccess.html#errorMonitor" class = "tsd-signature-type" data-tsd-kind = "Property" > errorMonitor< / a > < / div > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.errorMonitor< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:272< / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > This symbol shall be used to install a listener for only monitoring < code > ' error' < / code >
events. Listeners installed using this symbol are called before the regular
< code > ' error' < / code > listeners are called.< / p >
< / div > < div > < p > Installing a listener using this symbol does not change the behavior once an
< code > ' error' < / code > event is emitted, therefore the process will still crash if no
regular < code > ' error' < / code > listener is installed.< / p >
2022-04-02 12:59:10 +09:00
< / div > < / div > < / section > < / section > < section class = "tsd-panel-group tsd-member-group " > < h2 > Accessors< / h2 > < section class = "tsd-panel tsd-member tsd-kind-get-signature tsd-parent-kind-class" > < a id = "ports" class = "tsd-anchor" > < / a > < h3 > ports< / h3 > < ul class = "tsd-signatures tsd-kind-get-signature tsd-parent-kind-class" > < li class = "tsd-signature tsd-kind-icon" > < span class = "tsd-signature-symbol" > get< / span > ports< span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < a href = "GPIOPortMap.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOPortMap< / a > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < aside class = "tsd-sources" > < ul > < li > Defined in < a href = "https://github.com/chirimen-oh/node-web-gpio/blob/61f53c0/index.ts#L100" > index.ts:100< / a > < / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
2022-01-18 22:24:49 +09:00
< p > ポート情報取得処理< / p >
< / div > < / div > < h4 class = "tsd-returns-title" > Returns < a href = "GPIOPortMap.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOPortMap< / a > < / h4 > < div > < p > 現在のポート情報< / p >
< / div > < / li > < / ul > < / section > < / section > < section class = "tsd-panel-group tsd-member-group " > < h2 > Methods< / h2 > < section class = "tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a id = "addListener" class = "tsd-anchor" > < / a > < h3 > add< wbr / > Listener< / h3 > < ul class = "tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > add< wbr / > Listener< span class = "tsd-signature-symbol" > (< / span > eventName< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > , listener< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > => < / span > < span class = "tsd-signature-type" > void< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < a href = "GPIOAccess.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOAccess< / a > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.addListener< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:299< / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > Alias for < code > emitter.on(eventName, listener)< / code > .< / p >
< / div > < dl class = "tsd-comment-tags" > < dt > since< / dt > < dd > < p > v0.1.26< / p >
< / dd > < / dl > < / div > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > eventName: < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < / h5 > < / li > < li > < h5 > listener: < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > => < / span > < span class = "tsd-signature-type" > void< / span > < / h5 > < ul class = "tsd-parameters" > < li class = "tsd-parameter-signature" > < ul class = "tsd-signatures tsd-kind-type-literal tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > void< / span > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > < span class = "tsd-flag ts-flagRest" > Rest< / span > < span class = "tsd-signature-symbol" > ...< / span > args: < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < / h5 > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < span class = "tsd-signature-type" > void< / span > < / h4 > < / li > < / ul > < / li > < / ul > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < a href = "GPIOAccess.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOAccess< / a > < / h4 > < / li > < / ul > < / section > < section class = "tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a id = "emit" class = "tsd-anchor" > < / a > < h3 > emit< / h3 > < ul class = "tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > emit< span class = "tsd-signature-symbol" > (< / span > eventName< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > , < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > boolean< / span > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.emit< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:555< / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > Synchronously calls each of the listeners registered for the event named< code > eventName< / code > , in the order they were registered, passing the supplied arguments
to each.< / p >
< / div > < div > < p > Returns < code > true< / code > if the event had listeners, < code > false< / code > otherwise.< / p >
< pre > < code class = "language-js" > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-2" > EventEmitter< / span > < span class = "hl-1" > = < / span > < span class = "hl-3" > require< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' events' < / span > < span class = "hl-1" > );< / span > < br / > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-2" > myEmitter< / span > < span class = "hl-1" > = < / span > < span class = "hl-0" > new< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > EventEmitter< / span > < span class = "hl-1" > ();< / span > < br / > < br / > < span class = "hl-8" > // First listener< / span > < br / > < span class = "hl-5" > myEmitter< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > on< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' event' < / span > < span class = "hl-1" > , < / span > < span class = "hl-0" > function< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > 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-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' Helloooo! first listener' < / span > < span class = "hl-1" > );< / span > < br / > < span class = "hl-1" > });< / span > < br / > < span class = "hl-8" > // Second listener< / span > < br / > < span class = "hl-5" > myEmitter< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > on< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' event' < / span > < span class = "hl-1" > , < / span > < span class = "hl-0" > function< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > 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-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > `event with parameters < / span > < span class = "hl-0" > ${< / span > < span class = "hl-5" > arg1< / span > < span class = "hl-0" > }< / span > < span class = "hl-4" > , < / span > < span class = "hl-0" > ${< / span > < span class = "hl-5" > arg2< / span > < span class = "hl-0" > }< / span > < span class = "hl-4" > in second listener`< / span > < span class = "hl-1" > );< / span > < br / > < span class = "hl-1" > });< / span > < br / > < span class = "hl-8" > // Third listener< / span > < br / > < span class = "hl-5" > myEmitter< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > on< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' event' < / span > < span class = "hl-1" > , < / span > < span class = "hl-0" > function< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > 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-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-2" > parameters< / span > < span class = "hl-1" > = < / span > < span class = "hl-5" > args< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > join< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' , ' < / 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-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > `event with parameters < / span > < span class = "hl-0" > ${< / span > < span class = "hl-5" > parameters< / span > < span class = "hl-0" > }< / span > < span class = "hl-4" > 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-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-5" > myEmitter< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > listeners< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' event' < / span > < span class = "hl-1" > ));< / span > < br / > < br / > < span class = "hl-5" > myEmitter< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > emit< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' event' < / span > < span class = "hl-1" > , < / span > < span class = "hl-7" > 1< / span > < span class = "hl-1" > , < / span > < span class = "hl-7" > 2< / span > < span class = "hl-1" > , < / span > < span class = "hl-7" > 3< / span > < span class = "hl-1" > , < / span > < span class = "hl-7" > 4< / span > < span class = "hl-1" > , < / span > < span class = "hl-7" > 5< / span >
< / code > < / pre >
< / div > < dl class = "tsd-comment-tags" > < dt > since< / dt > < dd > < p > v0.1.26< / p >
< / dd > < / dl > < / div > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > eventName: < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < / h5 > < / li > < li > < h5 > < span class = "tsd-flag ts-flagRest" > Rest< / span > < span class = "tsd-signature-symbol" > ...< / span > args: < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < / h5 > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < span class = "tsd-signature-type" > boolean< / span > < / h4 > < / li > < / ul > < / section > < section class = "tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a id = "eventNames" class = "tsd-anchor" > < / a > < h3 > event< wbr / > Names< / h3 > < ul class = "tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > event< wbr / > Names< span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > []< / span > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.eventNames< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:614< / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > Returns an array listing the events for which the emitter has registered
listeners. The values in the array are strings or < code > Symbol< / code > s.< / p >
< / div > < div > < pre > < code class = "language-js" > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-2" > EventEmitter< / span > < span class = "hl-1" > = < / span > < span class = "hl-3" > require< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' events' < / span > < span class = "hl-1" > );< / span > < br / > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-2" > myEE< / span > < span class = "hl-1" > = < / span > < span class = "hl-0" > new< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > EventEmitter< / span > < span class = "hl-1" > ();< / span > < br / > < span class = "hl-5" > myEE< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > on< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' foo' < / span > < span class = "hl-1" > , () < / span > < span class = "hl-0" > => < / span > < span class = "hl-1" > {});< / span > < br / > < span class = "hl-5" > myEE< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > on< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' bar' < / span > < span class = "hl-1" > , () < / span > < span class = "hl-0" > => < / span > < span class = "hl-1" > {});< / span > < br / > < br / > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-2" > sym< / span > < span class = "hl-1" > = < / span > < span class = "hl-9" > Symbol< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' symbol' < / span > < span class = "hl-1" > );< / span > < br / > < span class = "hl-5" > myEE< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > on< / span > < span class = "hl-1" > (< / span > < span class = "hl-5" > sym< / span > < span class = "hl-1" > , () < / span > < span class = "hl-0" > => < / span > < span class = "hl-1" > {});< / span > < br / > < br / > < span class = "hl-5" > console< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-5" > myEE< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > eventNames< / span > < span class = "hl-1" > ());< / span > < br / > < span class = "hl-8" > // Prints: [ ' foo' , ' bar' , Symbol(symbol) ]< / span >
< / code > < / pre >
< / div > < dl class = "tsd-comment-tags" > < dt > since< / dt > < dd > < p > v6.0.0< / p >
< / dd > < / dl > < / div > < h4 class = "tsd-returns-title" > Returns < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > []< / span > < / h4 > < / li > < / ul > < / section > < section class = "tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a id = "getMaxListeners" class = "tsd-anchor" > < / a > < h3 > get< wbr / > Max< wbr / > Listeners< / h3 > < ul class = "tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > get< wbr / > Max< wbr / > Listeners< span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > number< / span > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.getMaxListeners< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:471< / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > Returns the current max listener value for the < code > EventEmitter< / code > which is either
set by < code > emitter.setMaxListeners(n)< / code > or defaults to < a href = "GPIOAccess.html#defaultMaxListeners" > defaultMaxListeners< / a > .< / p >
< / div > < dl class = "tsd-comment-tags" > < dt > since< / dt > < dd > < p > v1.0.0< / p >
< / dd > < / dl > < / div > < h4 class = "tsd-returns-title" > Returns < span class = "tsd-signature-type" > number< / span > < / h4 > < / li > < / ul > < / section > < section class = "tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a id = "listenerCount" class = "tsd-anchor" > < / a > < h3 > listener< wbr / > Count< / h3 > < ul class = "tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > listener< wbr / > Count< span class = "tsd-signature-symbol" > (< / span > eventName< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > number< / span > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.listenerCount< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:561< / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > Returns the number of listeners listening to the event named < code > eventName< / code > .< / p >
< / div > < dl class = "tsd-comment-tags" > < dt > since< / dt > < dd > < p > v3.2.0< / p >
< / dd > < / dl > < / div > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > eventName: < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < / h5 > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > The name of the event being listened for< / p >
< / div > < / div > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < span class = "tsd-signature-type" > number< / span > < / h4 > < / li > < / ul > < / section > < section class = "tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a id = "listeners" class = "tsd-anchor" > < / a > < h3 > listeners< / h3 > < ul class = "tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > listeners< span class = "tsd-signature-symbol" > (< / span > eventName< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > Function< / span > < span class = "tsd-signature-symbol" > []< / span > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.listeners< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:484< / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > Returns a copy of the array of listeners for the event named < code > eventName< / code > .< / p >
< / div > < div > < pre > < code class = "language-js" > < span class = "hl-5" > server< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > on< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' connection' < / span > < span class = "hl-1" > , (< / span > < span class = "hl-5" > stream< / span > < span class = "hl-1" > ) < / span > < span class = "hl-0" > => < / 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-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' 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-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-5" > util< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > inspect< / span > < span class = "hl-1" > (< / span > < span class = "hl-5" > server< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > listeners< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' connection' < / span > < span class = "hl-1" > )));< / span > < br / > < span class = "hl-8" > // Prints: [ [Function] ]< / span >
< / code > < / pre >
< / div > < dl class = "tsd-comment-tags" > < dt > since< / dt > < dd > < p > v0.1.26< / p >
< / dd > < / dl > < / div > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > eventName: < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < / h5 > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < span class = "tsd-signature-type" > Function< / span > < span class = "tsd-signature-symbol" > []< / span > < / h4 > < / li > < / ul > < / section > < section class = "tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a id = "off" class = "tsd-anchor" > < / a > < h3 > off< / h3 > < ul class = "tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > off< span class = "tsd-signature-symbol" > (< / span > eventName< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > , listener< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > => < / span > < span class = "tsd-signature-type" > void< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < a href = "GPIOAccess.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOAccess< / a > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.off< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:444< / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > Alias for < code > emitter.removeListener()< / code > .< / p >
< / div > < dl class = "tsd-comment-tags" > < dt > since< / dt > < dd > < p > v10.0.0< / p >
< / dd > < / dl > < / div > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > eventName: < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < / h5 > < / li > < li > < h5 > listener: < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > => < / span > < span class = "tsd-signature-type" > void< / span > < / h5 > < ul class = "tsd-parameters" > < li class = "tsd-parameter-signature" > < ul class = "tsd-signatures tsd-kind-type-literal tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > void< / span > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > < span class = "tsd-flag ts-flagRest" > Rest< / span > < span class = "tsd-signature-symbol" > ...< / span > args: < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < / h5 > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < span class = "tsd-signature-type" > void< / span > < / h4 > < / li > < / ul > < / li > < / ul > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < a href = "GPIOAccess.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOAccess< / a > < / h4 > < / li > < / ul > < / section > < section class = "tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a id = "on" class = "tsd-anchor" > < / a > < h3 > on< / h3 > < ul class = "tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > on< span class = "tsd-signature-symbol" > (< / span > eventName< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > , listener< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > => < / span > < span class = "tsd-signature-type" > void< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < a href = "GPIOAccess.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOAccess< / a > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.on< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:330< / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > Adds the < code > listener< / code > function to the end of the listeners array for the
event named < code > eventName< / code > . No checks are made to see if the < code > listener< / code > has
already been added. Multiple calls passing the same combination of < code > eventName< / code > and < code > listener< / code > will result in the < code > listener< / code > being added, and called, multiple
times.< / p >
< / div > < div > < pre > < code class = "language-js" > < span class = "hl-5" > server< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > on< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' connection' < / span > < span class = "hl-1" > , (< / span > < span class = "hl-5" > stream< / span > < span class = "hl-1" > ) < / span > < span class = "hl-0" > => < / 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-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' someone connected!' < / span > < span class = "hl-1" > );< / span > < br / > < span class = "hl-1" > });< / span >
< / code > < / pre >
< p > Returns a reference to the < code > EventEmitter< / code > , so that calls can be chained.< / p >
< p > By default, event listeners are invoked in the order they are added. The< code > emitter.prependListener()< / code > method can be used as an alternative to add the
event listener to the beginning of the listeners array.< / p >
< pre > < code class = "language-js" > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-2" > myEE< / span > < span class = "hl-1" > = < / span > < span class = "hl-0" > new< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > EventEmitter< / span > < span class = "hl-1" > ();< / span > < br / > < span class = "hl-5" > myEE< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > on< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' foo' < / span > < span class = "hl-1" > , () < / span > < span class = "hl-0" > => < / span > < span class = "hl-1" > < / span > < span class = "hl-5" > console< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' a' < / span > < span class = "hl-1" > ));< / span > < br / > < span class = "hl-5" > myEE< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > prependListener< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' foo' < / span > < span class = "hl-1" > , () < / span > < span class = "hl-0" > => < / span > < span class = "hl-1" > < / span > < span class = "hl-5" > console< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' b' < / span > < span class = "hl-1" > ));< / span > < br / > < span class = "hl-5" > myEE< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > emit< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' foo' < / span > < span class = "hl-1" > );< / span > < br / > < span class = "hl-8" > // Prints:< / span > < br / > < span class = "hl-8" > // b< / span > < br / > < span class = "hl-8" > // a< / span >
< / code > < / pre >
< / div > < dl class = "tsd-comment-tags" > < dt > since< / dt > < dd > < p > v0.1.101< / p >
< / dd > < / dl > < / div > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > eventName: < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < / h5 > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > The name of the event.< / p >
< / div > < / div > < / li > < li > < h5 > listener: < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > => < / span > < span class = "tsd-signature-type" > void< / span > < / h5 > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > The callback function< / p >
< / div > < / div > < ul class = "tsd-parameters" > < li class = "tsd-parameter-signature" > < ul class = "tsd-signatures tsd-kind-type-literal tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > void< / span > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > < span class = "tsd-flag ts-flagRest" > Rest< / span > < span class = "tsd-signature-symbol" > ...< / span > args: < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < / h5 > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < span class = "tsd-signature-type" > void< / span > < / h4 > < / li > < / ul > < / li > < / ul > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < a href = "GPIOAccess.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOAccess< / a > < / h4 > < / li > < / ul > < / section > < section class = "tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a id = "once" class = "tsd-anchor" > < / a > < h3 > once< / h3 > < ul class = "tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > once< span class = "tsd-signature-symbol" > (< / span > eventName< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > , listener< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > => < / span > < span class = "tsd-signature-type" > void< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < a href = "GPIOAccess.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOAccess< / a > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.once< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:359< / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > Adds a < strong > one-time< / strong > < code > listener< / code > function for the event named < code > eventName< / code > . The
next time < code > eventName< / code > is triggered, this listener is removed and then invoked.< / p >
< / div > < div > < pre > < code class = "language-js" > < span class = "hl-5" > server< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > once< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' connection' < / span > < span class = "hl-1" > , (< / span > < span class = "hl-5" > stream< / span > < span class = "hl-1" > ) < / span > < span class = "hl-0" > => < / 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-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' Ah, we have our first user!' < / span > < span class = "hl-1" > );< / span > < br / > < span class = "hl-1" > });< / span >
< / code > < / pre >
< p > Returns a reference to the < code > EventEmitter< / code > , so that calls can be chained.< / p >
< p > By default, event listeners are invoked in the order they are added. The< code > emitter.prependOnceListener()< / code > method can be used as an alternative to add the
event listener to the beginning of the listeners array.< / p >
< pre > < code class = "language-js" > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-2" > myEE< / span > < span class = "hl-1" > = < / span > < span class = "hl-0" > new< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > EventEmitter< / span > < span class = "hl-1" > ();< / span > < br / > < span class = "hl-5" > myEE< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > once< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' foo' < / span > < span class = "hl-1" > , () < / span > < span class = "hl-0" > => < / span > < span class = "hl-1" > < / span > < span class = "hl-5" > console< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' a' < / span > < span class = "hl-1" > ));< / span > < br / > < span class = "hl-5" > myEE< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > prependOnceListener< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' foo' < / span > < span class = "hl-1" > , () < / span > < span class = "hl-0" > => < / span > < span class = "hl-1" > < / span > < span class = "hl-5" > console< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' b' < / span > < span class = "hl-1" > ));< / span > < br / > < span class = "hl-5" > myEE< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > emit< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' foo' < / span > < span class = "hl-1" > );< / span > < br / > < span class = "hl-8" > // Prints:< / span > < br / > < span class = "hl-8" > // b< / span > < br / > < span class = "hl-8" > // a< / span >
< / code > < / pre >
< / div > < dl class = "tsd-comment-tags" > < dt > since< / dt > < dd > < p > v0.3.0< / p >
< / dd > < / dl > < / div > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > eventName: < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < / h5 > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > The name of the event.< / p >
< / div > < / div > < / li > < li > < h5 > listener: < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > => < / span > < span class = "tsd-signature-type" > void< / span > < / h5 > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > The callback function< / p >
< / div > < / div > < ul class = "tsd-parameters" > < li class = "tsd-parameter-signature" > < ul class = "tsd-signatures tsd-kind-type-literal tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > void< / span > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > < span class = "tsd-flag ts-flagRest" > Rest< / span > < span class = "tsd-signature-symbol" > ...< / span > args: < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < / h5 > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < span class = "tsd-signature-type" > void< / span > < / h4 > < / li > < / ul > < / li > < / ul > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < a href = "GPIOAccess.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOAccess< / a > < / h4 > < / li > < / ul > < / section > < section class = "tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a id = "prependListener" class = "tsd-anchor" > < / a > < h3 > prepend< wbr / > Listener< / h3 > < ul class = "tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > prepend< wbr / > Listener< span class = "tsd-signature-symbol" > (< / span > eventName< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > , listener< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > => < / span > < span class = "tsd-signature-type" > void< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < a href = "GPIOAccess.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOAccess< / a > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.prependListener< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:579< / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > Adds the < code > listener< / code > function to the < em > beginning< / em > of the listeners array for the
event named < code > eventName< / code > . No checks are made to see if the < code > listener< / code > has
already been added. Multiple calls passing the same combination of < code > eventName< / code > and < code > listener< / code > will result in the < code > listener< / code > being added, and called, multiple
times.< / p >
< / div > < div > < pre > < code class = "language-js" > < span class = "hl-5" > server< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > prependListener< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' connection' < / span > < span class = "hl-1" > , (< / span > < span class = "hl-5" > stream< / span > < span class = "hl-1" > ) < / span > < span class = "hl-0" > => < / 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-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' someone connected!' < / span > < span class = "hl-1" > );< / span > < br / > < span class = "hl-1" > });< / span >
< / code > < / pre >
< p > Returns a reference to the < code > EventEmitter< / code > , so that calls can be chained.< / p >
< / div > < dl class = "tsd-comment-tags" > < dt > since< / dt > < dd > < p > v6.0.0< / p >
< / dd > < / dl > < / div > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > eventName: < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < / h5 > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > The name of the event.< / p >
< / div > < / div > < / li > < li > < h5 > listener: < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > => < / span > < span class = "tsd-signature-type" > void< / span > < / h5 > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > The callback function< / p >
< / div > < / div > < ul class = "tsd-parameters" > < li class = "tsd-parameter-signature" > < ul class = "tsd-signatures tsd-kind-type-literal tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > void< / span > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > < span class = "tsd-flag ts-flagRest" > Rest< / span > < span class = "tsd-signature-symbol" > ...< / span > args: < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < / h5 > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < span class = "tsd-signature-type" > void< / span > < / h4 > < / li > < / ul > < / li > < / ul > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < a href = "GPIOAccess.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOAccess< / a > < / h4 > < / li > < / ul > < / section > < section class = "tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a id = "prependOnceListener" class = "tsd-anchor" > < / a > < h3 > prepend< wbr / > Once< wbr / > Listener< / h3 > < ul class = "tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > prepend< wbr / > Once< wbr / > Listener< span class = "tsd-signature-symbol" > (< / span > eventName< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > , listener< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > => < / span > < span class = "tsd-signature-type" > void< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < a href = "GPIOAccess.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOAccess< / a > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.prependOnceListener< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:595< / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > Adds a < strong > one-time< / strong > < code > listener< / code > function for the event named < code > eventName< / code > to the_beginning_ of the listeners array. The next time < code > eventName< / code > is triggered, this
listener is removed, and then invoked.< / p >
< / div > < div > < pre > < code class = "language-js" > < span class = "hl-5" > server< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > prependOnceListener< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' connection' < / span > < span class = "hl-1" > , (< / span > < span class = "hl-5" > stream< / span > < span class = "hl-1" > ) < / span > < span class = "hl-0" > => < / 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-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' Ah, we have our first user!' < / span > < span class = "hl-1" > );< / span > < br / > < span class = "hl-1" > });< / span >
< / code > < / pre >
< p > Returns a reference to the < code > EventEmitter< / code > , so that calls can be chained.< / p >
< / div > < dl class = "tsd-comment-tags" > < dt > since< / dt > < dd > < p > v6.0.0< / p >
< / dd > < / dl > < / div > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > eventName: < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < / h5 > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > The name of the event.< / p >
< / div > < / div > < / li > < li > < h5 > listener: < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > => < / span > < span class = "tsd-signature-type" > void< / span > < / h5 > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > The callback function< / p >
< / div > < / div > < ul class = "tsd-parameters" > < li class = "tsd-parameter-signature" > < ul class = "tsd-signatures tsd-kind-type-literal tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > void< / span > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > < span class = "tsd-flag ts-flagRest" > Rest< / span > < span class = "tsd-signature-symbol" > ...< / span > args: < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < / h5 > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < span class = "tsd-signature-type" > void< / span > < / h4 > < / li > < / ul > < / li > < / ul > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < a href = "GPIOAccess.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOAccess< / a > < / h4 > < / li > < / ul > < / section > < section class = "tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a id = "rawListeners" class = "tsd-anchor" > < / a > < h3 > raw< wbr / > Listeners< / h3 > < ul class = "tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > raw< wbr / > Listeners< span class = "tsd-signature-symbol" > (< / span > eventName< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > Function< / span > < span class = "tsd-signature-symbol" > []< / span > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.rawListeners< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:514< / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > Returns a copy of the array of listeners for the event named < code > eventName< / code > ,
including any wrappers (such as those created by < code > .once()< / code > ).< / p >
< / div > < div > < pre > < code class = "language-js" > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-2" > emitter< / span > < span class = "hl-1" > = < / span > < span class = "hl-0" > new< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > EventEmitter< / span > < span class = "hl-1" > ();< / span > < br / > < span class = "hl-5" > emitter< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > once< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' log' < / span > < span class = "hl-1" > , () < / span > < span class = "hl-0" > => < / span > < span class = "hl-1" > < / span > < span class = "hl-5" > console< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' log once' < / span > < span class = "hl-1" > ));< / span > < br / > < br / > < span class = "hl-8" > // Returns a new Array with a function `onceWrapper` which has a property< / span > < br / > < span class = "hl-8" > // `listener` which contains the original listener bound above< / span > < br / > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-2" > listeners< / span > < span class = "hl-1" > = < / span > < span class = "hl-5" > emitter< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > rawListeners< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' log' < / span > < span class = "hl-1" > );< / span > < br / > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-2" > logFnWrapper< / span > < span class = "hl-1" > = < / span > < span class = "hl-5" > listeners< / span > < span class = "hl-1" > [< / span > < span class = "hl-7" > 0< / span > < span class = "hl-1" > ];< / span > < br / > < br / > < span class = "hl-8" > // Logs " log once" to the console and does not unbind the `once` event< / span > < br / > < span class = "hl-5" > logFnWrapper< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > listener< / span > < span class = "hl-1" > ();< / span > < br / > < br / > < span class = "hl-8" > // Logs " log once" to the console and removes the listener< / span > < br / > < span class = "hl-3" > logFnWrapper< / span > < span class = "hl-1" > ();< / span > < br / > < br / > < span class = "hl-5" > emitter< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > on< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' log' < / span > < span class = "hl-1" > , () < / span > < span class = "hl-0" > => < / span > < span class = "hl-1" > < / span > < span class = "hl-5" > console< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' log persistently' < / span > < span class = "hl-1" > ));< / span > < br / > < span class = "hl-8" > // Will return a new Array with a single function bound by `.on()` above< / span > < br / > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-2" > newListeners< / span > < span class = "hl-1" > = < / span > < span class = "hl-5" > emitter< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > rawListeners< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' log' < / span > < span class = "hl-1" > );< / span > < br / > < br / > < span class = "hl-8" > // Logs " log persistently" twice< / span > < br / > < span class = "hl-5" > newListeners< / span > < span class = "hl-1" > [< / span > < span class = "hl-7" > 0< / span > < span class = "hl-1" > ]();< / span > < br / > < span class = "hl-5" > emitter< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > emit< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' log' < / span > < span class = "hl-1" > );< / span >
< / code > < / pre >
< / div > < dl class = "tsd-comment-tags" > < dt > since< / dt > < dd > < p > v9.4.0< / p >
< / dd > < / dl > < / div > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > eventName: < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < / h5 > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < span class = "tsd-signature-type" > Function< / span > < span class = "tsd-signature-symbol" > []< / span > < / h4 > < / li > < / ul > < / section > < section class = "tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a id = "removeAllListeners" class = "tsd-anchor" > < / a > < h3 > remove< wbr / > All< wbr / > Listeners< / h3 > < ul class = "tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > remove< wbr / > All< wbr / > Listeners< span class = "tsd-signature-symbol" > (< / span > event< span class = "tsd-signature-symbol" > ?: < / span > < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < a href = "GPIOAccess.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOAccess< / a > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.removeAllListeners< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:455< / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > Removes all listeners, or those of the specified < code > eventName< / code > .< / p >
< / div > < div > < p > It is bad practice to remove listeners added elsewhere in the code,
particularly when the < code > EventEmitter< / code > instance was created by some other
component or module (e.g. sockets or file streams).< / p >
< p > Returns a reference to the < code > EventEmitter< / code > , so that calls can be chained.< / p >
< / div > < dl class = "tsd-comment-tags" > < dt > since< / dt > < dd > < p > v0.1.26< / p >
< / dd > < / dl > < / div > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > < span class = "tsd-flag ts-flagOptional" > Optional< / span > event: < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < / h5 > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < a href = "GPIOAccess.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOAccess< / a > < / h4 > < / li > < / ul > < / section > < section class = "tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a id = "removeListener" class = "tsd-anchor" > < / a > < h3 > remove< wbr / > Listener< / h3 > < ul class = "tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > remove< wbr / > Listener< span class = "tsd-signature-symbol" > (< / span > eventName< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > , listener< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > => < / span > < span class = "tsd-signature-type" > void< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < a href = "GPIOAccess.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOAccess< / a > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.removeListener< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:439< / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > Removes the specified < code > listener< / code > from the listener array for the event named< code > eventName< / code > .< / p >
< / div > < div > < pre > < code class = "language-js" > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > callback< / span > < span class = "hl-1" > = (< / span > < span class = "hl-5" > stream< / span > < span class = "hl-1" > ) < / span > < span class = "hl-0" > => < / 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-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' 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-3" > on< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' connection' < / span > < span class = "hl-1" > , < / span > < span class = "hl-5" > callback< / span > < span class = "hl-1" > );< / span > < br / > < span class = "hl-8" > // ...< / span > < br / > < span class = "hl-5" > server< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > removeListener< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' connection' < / span > < span class = "hl-1" > , < / span > < span class = "hl-5" > callback< / span > < span class = "hl-1" > );< / span >
< / code > < / pre >
< p > < code > removeListener()< / code > will remove, at most, one instance of a listener from the
listener array. If any single listener has been added multiple times to the
listener array for the specified < code > eventName< / code > , then < code > removeListener()< / code > must be
called multiple times to remove each instance.< / p >
< p > Once an event is emitted, all listeners attached to it at the
time of emitting are called in order. This implies that any< code > removeListener()< / code > or < code > removeAllListeners()< / code > calls < em > after< / em > emitting and_before_ the last listener finishes execution will
not remove them from< code > emit()< / code > in progress. Subsequent events behave as expected.< / p >
< pre > < code class = "language-js" > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-2" > myEmitter< / span > < span class = "hl-1" > = < / span > < span class = "hl-0" > new< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > MyEmitter< / span > < span class = "hl-1" > ();< / span > < br / > < br / > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > callbackA< / span > < span class = "hl-1" > = () < / span > < span class = "hl-0" > => < / 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-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' 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-3" > removeListener< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' 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-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > callbackB< / span > < span class = "hl-1" > = () < / span > < span class = "hl-0" > => < / 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-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' 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-3" > on< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' 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-3" > on< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' event' < / span > < span class = "hl-1" > , < / span > < span class = "hl-5" > callbackB< / span > < span class = "hl-1" > );< / span > < br / > < br / > < span class = "hl-8" > // callbackA removes listener callbackB but it will still be called.< / span > < br / > < span class = "hl-8" > // Internal listener array at time of emit [callbackA, callbackB]< / span > < br / > < span class = "hl-5" > myEmitter< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > emit< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' event' < / span > < span class = "hl-1" > );< / span > < br / > < span class = "hl-8" > // Prints:< / span > < br / > < span class = "hl-8" > // A< / span > < br / > < span class = "hl-8" > // B< / span > < br / > < br / > < span class = "hl-8" > // callbackB is now removed.< / span > < br / > < span class = "hl-8" > // Internal listener array [callbackA]< / span > < br / > < span class = "hl-5" > myEmitter< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > emit< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' event' < / span > < span class = "hl-1" > );< / span > < br / > < span class = "hl-8" > // Prints:< / span > < br / > < span class = "hl-8" > // A< / span >
< / code > < / pre >
< p > Because listeners are managed using an internal array, calling this will
change the position indices of any listener registered < em > after< / em > the listener
being removed. This will not impact the order in which listeners are called,
but it means that any copies of the listener array as returned by
the < code > emitter.listeners()< / code > method will need to be recreated.< / p >
< p > When a single function has been added as a handler multiple times for a single
event (as in the example below), < code > removeListener()< / code > will remove the most
recently added instance. In the example the < code > once(' ping' )< / code > listener is removed:< / p >
< pre > < code class = "language-js" > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-2" > ee< / span > < span class = "hl-1" > = < / span > < span class = "hl-0" > new< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > EventEmitter< / span > < span class = "hl-1" > ();< / span > < br / > < br / > < span class = "hl-0" > function< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > 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-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' 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-3" > on< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' 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-3" > once< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' 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-3" > removeListener< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' 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-3" > emit< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' ping' < / span > < span class = "hl-1" > );< / span > < br / > < span class = "hl-5" > ee< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > emit< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' ping' < / span > < span class = "hl-1" > );< / span >
< / code > < / pre >
< p > Returns a reference to the < code > EventEmitter< / code > , so that calls can be chained.< / p >
< / div > < dl class = "tsd-comment-tags" > < dt > since< / dt > < dd > < p > v0.1.26< / p >
< / dd > < / dl > < / div > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > eventName: < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < / h5 > < / li > < li > < h5 > listener: < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > => < / span > < span class = "tsd-signature-type" > void< / span > < / h5 > < ul class = "tsd-parameters" > < li class = "tsd-parameter-signature" > < ul class = "tsd-signatures tsd-kind-type-literal tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > < span class = "tsd-signature-symbol" > (< / span > < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > void< / span > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > < span class = "tsd-flag ts-flagRest" > Rest< / span > < span class = "tsd-signature-symbol" > ...< / span > args: < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < / h5 > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < span class = "tsd-signature-type" > void< / span > < / h4 > < / li > < / ul > < / li > < / ul > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < a href = "GPIOAccess.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOAccess< / a > < / h4 > < / li > < / ul > < / section > < section class = "tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a id = "setMaxListeners" class = "tsd-anchor" > < / a > < h3 > set< wbr / > Max< wbr / > Listeners< / h3 > < ul class = "tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > set< wbr / > Max< wbr / > Listeners< span class = "tsd-signature-symbol" > (< / span > n< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > number< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < a href = "GPIOAccess.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOAccess< / a > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.setMaxListeners< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:465< / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > By default < code > EventEmitter< / code > s will print a warning if more than < code > 10< / code > listeners are
added for a particular event. This is a useful default that helps finding
memory leaks. The < code > emitter.setMaxListeners()< / code > method allows the limit to be
modified for this specific < code > EventEmitter< / code > instance. The value can be set to< code > Infinity< / code > (or < code > 0< / code > ) to indicate an unlimited number of listeners.< / p >
< / div > < div > < p > Returns a reference to the < code > EventEmitter< / code > , so that calls can be chained.< / p >
< / div > < dl class = "tsd-comment-tags" > < dt > since< / dt > < dd > < p > v0.3.5< / p >
2022-04-02 12:59:10 +09:00
< / dd > < / dl > < / div > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > n: < span class = "tsd-signature-type" > number< / span > < / h5 > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < a href = "GPIOAccess.html" class = "tsd-signature-type" data-tsd-kind = "Class" > GPIOAccess< / a > < / h4 > < / li > < / ul > < / section > < section class = "tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class" > < a id = "unexportAll" class = "tsd-anchor" > < / a > < h3 > unexport< wbr / > All< / h3 > < ul class = "tsd-signatures tsd-kind-method tsd-parent-kind-class" > < li class = "tsd-signature tsd-kind-icon" > unexport< wbr / > All< span class = "tsd-signature-symbol" > (< / span > < 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" > void< / span > < span class = "tsd-signature-symbol" > > < / span > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < aside class = "tsd-sources" > < ul > < li > Defined in < a href = "https://github.com/chirimen-oh/node-web-gpio/blob/61f53c0/index.ts#L109" > index.ts:109< / a > < / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
2022-01-18 22:24:49 +09:00
< p > Unexport all exported GPIO ports.
全てのポート開放をする< / p >
< / div > < / 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" > void< / span > < span class = "tsd-signature-symbol" > > < / span > < / h4 > < div > < p > ポート開放結果< / p >
< / div > < / li > < / ul > < / section > < section class = "tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external" > < a id = "getEventListeners" class = "tsd-anchor" > < / a > < h3 > < span class = "tsd-flag ts-flagStatic" > Static< / span > get< wbr / > Event< wbr / > Listeners< / h3 > < ul class = "tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > get< wbr / > Event< wbr / > Listeners< span class = "tsd-signature-symbol" > (< / span > emitter< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > DOMEventTarget< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > EventEmitter< / span > , name< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > Function< / span > < span class = "tsd-signature-symbol" > []< / span > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.getEventListeners< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:262< / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > Returns a copy of the array of listeners for the event named < code > eventName< / code > .< / p >
< / div > < div > < p > For < code > EventEmitter< / code > s this behaves exactly the same as calling < code > .listeners< / code > on
the emitter.< / p >
< p > For < code > EventTarget< / code > s this is the only way to get the event listeners for the
event target. This is useful for debugging and diagnostic purposes.< / p >
< pre > < code class = "language-js" > < span class = "hl-0" > const< / span > < span class = "hl-1" > { < / span > < span class = "hl-2" > getEventListeners< / span > < span class = "hl-1" > , < / span > < span class = "hl-2" > EventEmitter< / span > < span class = "hl-1" > } = < / span > < span class = "hl-3" > require< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' events' < / span > < span class = "hl-1" > );< / span > < br / > < br / > < span class = "hl-1" > {< / span > < br / > < span class = "hl-1" > < / span > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-2" > ee< / span > < span class = "hl-1" > = < / span > < span class = "hl-0" > new< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > EventEmitter< / span > < span class = "hl-1" > ();< / span > < br / > < span class = "hl-1" > < / span > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > listener< / span > < span class = "hl-1" > = () < / span > < span class = "hl-0" > => < / span > < span class = "hl-1" > < / span > < span class = "hl-5" > console< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' 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-3" > on< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' 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-3" > getEventListeners< / span > < span class = "hl-1" > (< / span > < span class = "hl-5" > ee< / span > < span class = "hl-1" > , < / span > < span class = "hl-4" > ' foo' < / span > < span class = "hl-1" > ); < / span > < span class = "hl-8" > // [listener]< / span > < br / > < span class = "hl-1" > }< / span > < br / > < span class = "hl-1" > {< / span > < br / > < span class = "hl-1" > < / span > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-2" > et< / span > < span class = "hl-1" > = < / span > < span class = "hl-0" > new< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > EventTarget< / span > < span class = "hl-1" > ();< / span > < br / > < span class = "hl-1" > < / span > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > listener< / span > < span class = "hl-1" > = () < / span > < span class = "hl-0" > => < / span > < span class = "hl-1" > < / span > < span class = "hl-5" > console< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' 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-3" > addEventListener< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' 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-3" > getEventListeners< / span > < span class = "hl-1" > (< / span > < span class = "hl-5" > et< / span > < span class = "hl-1" > , < / span > < span class = "hl-4" > ' foo' < / span > < span class = "hl-1" > ); < / span > < span class = "hl-8" > // [listener]< / span > < br / > < span class = "hl-1" > }< / span >
< / code > < / pre >
< / div > < dl class = "tsd-comment-tags" > < dt > since< / dt > < dd > < p > v15.2.0< / p >
< / dd > < / dl > < / div > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > emitter: < span class = "tsd-signature-type" > DOMEventTarget< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > EventEmitter< / span > < / h5 > < / li > < li > < h5 > name: < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < / h5 > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < span class = "tsd-signature-type" > Function< / span > < span class = "tsd-signature-symbol" > []< / span > < / h4 > < / li > < / ul > < / section > < section class = "tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external" > < a id = "listenerCount-1" class = "tsd-anchor" > < / a > < h3 > < span class = "tsd-flag ts-flagStatic" > Static< / span > listener< wbr / > Count< / h3 > < ul class = "tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > listener< wbr / > Count< span class = "tsd-signature-symbol" > (< / span > emitter< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > EventEmitter< / span > , eventName< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > number< / span > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.listenerCount< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:234< / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > A class method that returns the number of listeners for the given < code > eventName< / code > registered on the given < code > emitter< / code > .< / p >
< / div > < div > < pre > < code class = "language-js" > < span class = "hl-0" > const< / span > < span class = "hl-1" > { < / span > < span class = "hl-2" > EventEmitter< / span > < span class = "hl-1" > , < / span > < span class = "hl-2" > listenerCount< / span > < span class = "hl-1" > } = < / span > < span class = "hl-3" > require< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' events' < / span > < span class = "hl-1" > );< / span > < br / > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-2" > myEmitter< / span > < span class = "hl-1" > = < / span > < span class = "hl-0" > new< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > EventEmitter< / span > < span class = "hl-1" > ();< / span > < br / > < span class = "hl-5" > myEmitter< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > on< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' event' < / span > < span class = "hl-1" > , () < / span > < span class = "hl-0" > => < / span > < span class = "hl-1" > {});< / span > < br / > < span class = "hl-5" > myEmitter< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > on< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' event' < / span > < span class = "hl-1" > , () < / span > < span class = "hl-0" > => < / span > < span class = "hl-1" > {});< / span > < br / > < span class = "hl-5" > console< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-3" > listenerCount< / span > < span class = "hl-1" > (< / span > < span class = "hl-5" > myEmitter< / span > < span class = "hl-1" > , < / span > < span class = "hl-4" > ' event' < / span > < span class = "hl-1" > ));< / span > < br / > < span class = "hl-8" > // Prints: 2< / span >
< / code > < / pre >
< / div > < dl class = "tsd-comment-tags" > < dt > since< / dt > < dd > < p > v0.9.12< / p >
< / dd > < dt > deprecated< / dt > < dd > < p > Since v3.2.0 - Use < code > listenerCount< / code > instead.< / p >
< / dd > < / dl > < / div > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > emitter: < span class = "tsd-signature-type" > EventEmitter< / span > < / h5 > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > The emitter to query< / p >
< / div > < / div > < / li > < li > < h5 > eventName: < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < / h5 > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > The event name< / p >
< / div > < / div > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < span class = "tsd-signature-type" > number< / span > < / h4 > < / li > < / ul > < / section > < section class = "tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external" > < a id = "on-1" class = "tsd-anchor" > < / a > < h3 > < span class = "tsd-flag ts-flagStatic" > Static< / span > on< / h3 > < ul class = "tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > on< span class = "tsd-signature-symbol" > (< / span > emitter< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > EventEmitter< / span > , eventName< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > string< / span > , options< span class = "tsd-signature-symbol" > ?: < / span > < span class = "tsd-signature-type" > StaticEventEmitterOptions< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > AsyncIterableIterator< / span > < span class = "tsd-signature-symbol" > < < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > > < / span > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.on< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:217< / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > ```js
const { on, EventEmitter } = require(' events' );< / p >
< / div > < div > < p > (async () => {
const ee = new EventEmitter();< / p >
< p > // Emit later on
process.nextTick(() => {
ee.emit(' foo' , ' bar' );
ee.emit(' foo' , 42);
});< / p >
< p > for await (const event of on(ee, ' foo' )) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints [' bar' ] [42]
}
// Unreachable here
})();< / p >
< pre > < code > < br / > < span class = "hl-5" > Returns< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > an< / span > < span class = "hl-1" > < / span > < span class = "hl-4" > `AsyncIterator`< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > that< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > iterates< / span > < span class = "hl-1" > < / span > < span class = "hl-4" > `eventName`< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > events< / span > < span class = "hl-1" > . < / span > < span class = "hl-5" > It< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > will< / span > < span class = "hl-1" > < / span > < span class = "hl-6" > throw< / span > < br / > < span class = "hl-6" > if< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > the< / span > < span class = "hl-1" > < / span > < span class = "hl-4" > `EventEmitter`< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > emits< / span > < span class = "hl-1" > < / span > < span class = "hl-4" > `' error' `< / span > < span class = "hl-1" > . < / span > < span class = "hl-5" > It< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > removes< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > all< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > listeners< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > when< / span > < br / > < span class = "hl-5" > exiting< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > the< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > loop< / span > < span class = "hl-1" > . < / span > < span class = "hl-5" > The< / span > < span class = "hl-1" > < / span > < span class = "hl-4" > `value`< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > returned< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > by< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > each< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > iteration< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > is< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > an< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > array< / span > < br / > < span class = "hl-5" > composed< / span > < span class = "hl-1" > < / span > < span class = "hl-0" > of< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > the< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > emitted< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > event< / span > < span class = "hl-1" > < / span > < span class = "hl-0" > arguments< / span > < span class = "hl-1" > .< / span > < br / > < br / > < span class = "hl-5" > An< / span > < span class = "hl-1" > < / span > < span class = "hl-4" > `AbortSignal`< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > can< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > be< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > used< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > to< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > cancel< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > waiting< / span > < span class = "hl-1" > < / span > < span class = "hl-5" > on< / span > < span class = "hl-1" > < / span > < span class = "hl-10" > events< / span > < span class = "hl-1" > :< / span > < br / > < br / > < span class = "hl-4" > ```js< / span > < br / > < span class = "hl-4" > const { on, EventEmitter } = require(' events' );< / span > < br / > < span class = "hl-4" > const ac = new AbortController();< / span > < br / > < br / > < span class = "hl-4" > (async () => {< / span > < br / > < span class = "hl-4" > const ee = new EventEmitter();< / span > < br / > < br / > < span class = "hl-4" > // Emit later on< / span > < br / > < span class = "hl-4" > process.nextTick(() => {< / span > < br / > < span class = "hl-4" > ee.emit(' foo' , ' bar' );< / span > < br / > < span class = "hl-4" > ee.emit(' foo' , 42);< / span > < br / > < span class = "hl-4" > });< / span > < br / > < br / > < span class = "hl-4" > for await (const event of on(ee, ' foo' , { signal: ac.signal })) {< / span > < br / > < span class = "hl-4" > // The execution of this inner block is synchronous and it< / span > < br / > < span class = "hl-4" > // processes one event at a time (even with await). Do not use< / span > < br / > < span class = "hl-4" > // if concurrent execution is required.< / span > < br / > < span class = "hl-4" > console.log(event); // prints [' bar' ] [42]< / span > < br / > < span class = "hl-4" > }< / span > < br / > < span class = "hl-4" > // Unreachable here< / span > < br / > < span class = "hl-4" > })();< / span > < br / > < br / > < span class = "hl-4" > process.nextTick(() => ac.abort());< / span >
< / code > < / pre >
< / div > < dl class = "tsd-comment-tags" > < dt > since< / dt > < dd > < p > v13.6.0, v12.16.0< / p >
< / dd > < / dl > < / div > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > emitter: < span class = "tsd-signature-type" > EventEmitter< / span > < / h5 > < / li > < li > < h5 > eventName: < span class = "tsd-signature-type" > string< / span > < / h5 > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > The name of the event being listened for< / p >
< / div > < / div > < / li > < li > < h5 > < span class = "tsd-flag ts-flagOptional" > Optional< / span > options: < span class = "tsd-signature-type" > StaticEventEmitterOptions< / span > < / h5 > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < span class = "tsd-signature-type" > AsyncIterableIterator< / span > < span class = "tsd-signature-symbol" > < < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > > < / span > < / h4 > < div > < p > that iterates < code > eventName< / code > events emitted by the < code > emitter< / code > < / p >
< / div > < / li > < / ul > < / section > < section class = "tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external" > < a id = "once-1" class = "tsd-anchor" > < / a > < h3 > < span class = "tsd-flag ts-flagStatic" > Static< / span > once< / h3 > < ul class = "tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external" > < li class = "tsd-signature tsd-kind-icon" > once< span class = "tsd-signature-symbol" > (< / span > emitter< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > NodeEventTarget< / span > , eventName< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > , options< span class = "tsd-signature-symbol" > ?: < / span > < span class = "tsd-signature-type" > StaticEventEmitterOptions< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > Promise< / span > < span class = "tsd-signature-symbol" > < < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > > < / span > < / li > < li class = "tsd-signature tsd-kind-icon" > once< span class = "tsd-signature-symbol" > (< / span > emitter< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > DOMEventTarget< / span > , eventName< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > string< / span > , options< span class = "tsd-signature-symbol" > ?: < / span > < span class = "tsd-signature-type" > StaticEventEmitterOptions< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > Promise< / span > < span class = "tsd-signature-symbol" > < < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > > < / span > < / li > < / ul > < ul class = "tsd-descriptions" > < li class = "tsd-description" > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.once< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:157< / li > < / ul > < / aside > < div class = "tsd-comment tsd-typography" > < div class = "lead" >
< p > Creates a < code > Promise< / code > that is fulfilled when the < code > EventEmitter< / code > emits the given
event or that is rejected if the < code > EventEmitter< / code > emits < code > ' error' < / code > while waiting.
The < code > Promise< / code > will resolve with an array of all the arguments emitted to the
given event.< / p >
< / div > < div > < p > This method is intentionally generic and works with the web platform < a href = "https://dom.spec.whatwg.org/#interface-eventtarget" > EventTarget< / a > interface, which has no special< code > ' error' < / code > event
semantics and does not listen to the < code > ' error' < / code > event.< / p >
< pre > < code class = "language-js" > < span class = "hl-0" > const< / span > < span class = "hl-1" > { < / span > < span class = "hl-2" > once< / span > < span class = "hl-1" > , < / span > < span class = "hl-2" > EventEmitter< / span > < span class = "hl-1" > } = < / span > < span class = "hl-3" > require< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' events' < / span > < span class = "hl-1" > );< / span > < br / > < br / > < span class = "hl-0" > async< / span > < span class = "hl-1" > < / span > < span class = "hl-0" > function< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > run< / span > < span class = "hl-1" > () {< / span > < br / > < span class = "hl-1" > < / span > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-2" > ee< / span > < span class = "hl-1" > = < / span > < span class = "hl-0" > new< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > EventEmitter< / span > < span class = "hl-1" > ();< / span > < br / > < br / > < span class = "hl-1" > < / span > < span class = "hl-5" > process< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > nextTick< / span > < span class = "hl-1" > (() < / span > < span class = "hl-0" > => < / 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-3" > emit< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' myevent' < / span > < span class = "hl-1" > , < / span > < span class = "hl-7" > 42< / span > < span class = "hl-1" > );< / span > < br / > < span class = "hl-1" > });< / span > < br / > < br / > < span class = "hl-1" > < / span > < span class = "hl-0" > const< / span > < span class = "hl-1" > [< / span > < span class = "hl-2" > value< / span > < span class = "hl-1" > ] = < / span > < span class = "hl-6" > await< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > once< / span > < span class = "hl-1" > (< / span > < span class = "hl-5" > ee< / span > < span class = "hl-1" > , < / span > < span class = "hl-4" > ' myevent' < / 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-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-5" > value< / span > < span class = "hl-1" > );< / span > < br / > < br / > < span class = "hl-1" > < / span > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-2" > err< / span > < span class = "hl-1" > = < / span > < span class = "hl-0" > new< / span > < span class = "hl-1" > < / span > < span class = "hl-9" > Error< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' kaboom' < / span > < span class = "hl-1" > );< / span > < br / > < span class = "hl-1" > < / span > < span class = "hl-5" > process< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > nextTick< / span > < span class = "hl-1" > (() < / span > < span class = "hl-0" > => < / 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-3" > emit< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' 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-1" > < / span > < span class = "hl-6" > try< / span > < span class = "hl-1" > {< / span > < br / > < span class = "hl-1" > < / span > < span class = "hl-6" > await< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > once< / span > < span class = "hl-1" > (< / span > < span class = "hl-5" > ee< / span > < span class = "hl-1" > , < / span > < span class = "hl-4" > ' myevent' < / span > < span class = "hl-1" > );< / span > < br / > < span class = "hl-1" > } < / span > < span class = "hl-6" > 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-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' 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 > < br / > < span class = "hl-1" > }< / span > < br / > < br / > < span class = "hl-3" > run< / span > < span class = "hl-1" > ();< / span >
< / code > < / pre >
< p > The special handling of the < code > ' error' < / code > event is only used when < code > events.once()< / code > is used to wait for another event. If < code > events.once()< / code > is used to wait for the
' < code > error' < / code > event itself, then it is treated as any other kind of event without
special handling:< / p >
< pre > < code class = "language-js" > < span class = "hl-0" > const< / span > < span class = "hl-1" > { < / span > < span class = "hl-2" > EventEmitter< / span > < span class = "hl-1" > , < / span > < span class = "hl-2" > once< / span > < span class = "hl-1" > } = < / span > < span class = "hl-3" > require< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' events' < / span > < span class = "hl-1" > );< / span > < br / > < br / > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-2" > ee< / span > < span class = "hl-1" > = < / span > < span class = "hl-0" > new< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > EventEmitter< / span > < span class = "hl-1" > ();< / span > < br / > < br / > < span class = "hl-3" > once< / span > < span class = "hl-1" > (< / span > < span class = "hl-5" > ee< / span > < span class = "hl-1" > , < / span > < span class = "hl-4" > ' error' < / span > < span class = "hl-1" > )< / span > < br / > < span class = "hl-1" > .< / span > < span class = "hl-3" > then< / span > < span class = "hl-1" > (([< / span > < span class = "hl-5" > err< / span > < span class = "hl-1" > ]) < / span > < span class = "hl-0" > => < / span > < span class = "hl-1" > < / span > < span class = "hl-5" > console< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' 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-3" > catch< / span > < span class = "hl-1" > ((< / span > < span class = "hl-5" > err< / span > < span class = "hl-1" > ) < / span > < span class = "hl-0" > => < / span > < span class = "hl-1" > < / span > < span class = "hl-5" > console< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' 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-3" > emit< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' error' < / span > < span class = "hl-1" > , < / span > < span class = "hl-0" > new< / span > < span class = "hl-1" > < / span > < span class = "hl-9" > Error< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' boom' < / span > < span class = "hl-1" > ));< / span > < br / > < br / > < span class = "hl-8" > // Prints: ok boom< / span >
< / code > < / pre >
< p > An < code > AbortSignal< / code > can be used to cancel waiting for the event:< / p >
< pre > < code class = "language-js" > < span class = "hl-0" > const< / span > < span class = "hl-1" > { < / span > < span class = "hl-2" > EventEmitter< / span > < span class = "hl-1" > , < / span > < span class = "hl-2" > once< / span > < span class = "hl-1" > } = < / span > < span class = "hl-3" > require< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' events' < / span > < span class = "hl-1" > );< / span > < br / > < br / > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-2" > ee< / span > < span class = "hl-1" > = < / span > < span class = "hl-0" > new< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > EventEmitter< / span > < span class = "hl-1" > ();< / span > < br / > < span class = "hl-0" > const< / span > < span class = "hl-1" > < / span > < span class = "hl-2" > ac< / span > < span class = "hl-1" > = < / span > < span class = "hl-0" > new< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > AbortController< / span > < span class = "hl-1" > ();< / span > < br / > < br / > < span class = "hl-0" > async< / span > < span class = "hl-1" > < / span > < span class = "hl-0" > function< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > 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-6" > try< / span > < span class = "hl-1" > {< / span > < br / > < span class = "hl-1" > < / span > < span class = "hl-6" > await< / span > < span class = "hl-1" > < / span > < span class = "hl-3" > 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-3" > log< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' event emitted!' < / span > < span class = "hl-1" > );< / span > < br / > < span class = "hl-1" > } < / span > < span class = "hl-6" > 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-6" > 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-4" > ' 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-3" > error< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' Waiting for the event was canceled!' < / span > < span class = "hl-1" > );< / span > < br / > < span class = "hl-1" > } < / span > < span class = "hl-6" > 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-3" > error< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' 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-3" > foo< / span > < span class = "hl-1" > (< / span > < span class = "hl-5" > ee< / span > < span class = "hl-1" > , < / span > < span class = "hl-4" > ' 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-3" > abort< / span > < span class = "hl-1" > (); < / span > < span class = "hl-8" > // Abort waiting for the event< / span > < br / > < span class = "hl-5" > ee< / span > < span class = "hl-1" > .< / span > < span class = "hl-3" > emit< / span > < span class = "hl-1" > (< / span > < span class = "hl-4" > ' foo' < / span > < span class = "hl-1" > ); < / span > < span class = "hl-8" > // Prints: Waiting for the event was canceled!< / span >
< / code > < / pre >
< / div > < dl class = "tsd-comment-tags" > < dt > since< / dt > < dd > < p > v11.13.0, v10.16.0< / p >
< / dd > < / dl > < / div > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > emitter: < span class = "tsd-signature-type" > NodeEventTarget< / span > < / h5 > < / li > < li > < h5 > eventName: < span class = "tsd-signature-type" > string< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > symbol< / span > < / h5 > < / li > < li > < h5 > < span class = "tsd-flag ts-flagOptional" > Optional< / span > options: < span class = "tsd-signature-type" > StaticEventEmitterOptions< / span > < / h5 > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < span class = "tsd-signature-type" > Promise< / span > < span class = "tsd-signature-symbol" > < < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > > < / span > < / h4 > < / li > < li class = "tsd-description" > < aside class = "tsd-sources" > < p > Inherited from EventEmitter.once< / p > < ul > < li > Defined in node_modules/@types/node/events.d.ts:158< / li > < / ul > < / aside > < h4 class = "tsd-parameters-title" > Parameters< / h4 > < ul class = "tsd-parameters" > < li > < h5 > emitter: < span class = "tsd-signature-type" > DOMEventTarget< / span > < / h5 > < / li > < li > < h5 > eventName: < span class = "tsd-signature-type" > string< / span > < / h5 > < / li > < li > < h5 > < span class = "tsd-flag ts-flagOptional" > Optional< / span > options: < span class = "tsd-signature-type" > StaticEventEmitterOptions< / span > < / h5 > < / li > < / ul > < h4 class = "tsd-returns-title" > Returns < span class = "tsd-signature-type" > Promise< / span > < span class = "tsd-signature-symbol" > < < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > > < / span > < / h4 > < / li > < / ul > < / section > < / section > < / div > < div class = "col-4 col-menu menu-sticky-wrap menu-highlight" > < nav class = "tsd-navigation primary" > < ul > < li class = "" > < a href = "../modules.html" > Exports< / a > < / li > < / ul > < / nav > < nav class = "tsd-navigation secondary menu-sticky" > < ul > < li class = "current tsd-kind-class" > < a href = "GPIOAccess.html" class = "tsd-kind-icon" > GPIOAccess< / a > < ul > < li class = "tsd-kind-constructor tsd-parent-kind-class tsd-is-overwrite" > < a href = "GPIOAccess.html#constructor" class = "tsd-kind-icon" > constructor< / a > < / li > < li class = "tsd-kind-property tsd-parent-kind-class tsd-is-private" > < a href = "GPIOAccess.html#_ports" class = "tsd-kind-icon" > _ports< / a > < / li > < li class = "tsd-kind-property tsd-parent-kind-class" > < a href = "GPIOAccess.html#onchange" class = "tsd-kind-icon" > onchange< / a > < / li > < li class = "tsd-kind-property tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external" > < a href = "GPIOAccess.html#captureRejectionSymbol" class = "tsd-kind-icon" > capture< wbr / > Rejection< wbr / > Symbol< / a > < / li > < li class = "tsd-kind-property tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external" > < a href = "GPIOAccess.html#captureRejections" class = "tsd-kind-icon" > capture< wbr / > Rejections< / a > < / li > < li class = "tsd-kind-property tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external" > < a href = "GPIOAccess.html#defaultMaxListeners" class = "tsd-kind-icon" > default< wbr / > Max< wbr / > Listeners< / a > < / li > < li class = "tsd-kind-property tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external" > < a href = "GPIOAccess.html#errorMonitor" class = "tsd-kind-icon" > error< wbr / > Monitor< / a > < / li > < li class = "tsd-kind-get-signature tsd-parent-kind-class" > < a href = "GPIOAccess.html#ports" class = "tsd-kind-icon" > ports< / a > < / li > < li class = "tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a href = "GPIOAccess.html#addListener" class = "tsd-kind-icon" > add< wbr / > Listener< / a > < / li > < li class = "tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a href = "GPIOAccess.html#emit" class = "tsd-kind-icon" > emit< / a > < / li > < li class = "tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a href = "GPIOAccess.html#eventNames" class = "tsd-kind-icon" > event< wbr / > Names< / a > < / li > < li class = "tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a href = "GPIOAccess.html#getMaxListeners" class = "tsd-kind-icon" > get< wbr / > Max< wbr / > Listeners< / a > < / li > < li class = "tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external" > < a href = "GPIOAccess.html#listenerCount" class = "tsd-kind