Search the reference...
/
BuildDocsReferenceGuidesBlogDiscord/node:events/default/EventEmitterAsyncResourceM[events.captureRejectionSymbol]MaddListenerPasyncIdPasyncResourceCoconstructorMemitMemitDestroyMeventNamesMgetMaxListenersMlistenerCountMlistenersMoffMonMonceMprependListenerMprependOnceListenerMrawListenersMremoveAllListenersMremoveListenerMsetMaxListenersPtriggerAsyncIdclass
events.default.EventEmitterAsyncResource { strictEqual(executionAsyncId(), ee1.asyncId); strictEqual(triggerAsyncId(), ee1.triggerAsyncId); }); const ee2 = new EventEmitter(); // 'foo' listeners on ordinary EventEmitters that do not track async // context, however, run in the same async context as the emit(). ee2.on('foo', () => { notStrictEqual(executionAsyncId(), ee2.asyncId); notStrictEqual(triggerAsyncId(), ee2.triggerAsyncId); }); Promise.resolve().then(() => { ee1.emit('foo'); ee2.emit('foo'); }); ``` The `EventEmitterAsyncResource` class has the same methods and takes the same options as `EventEmitter` and `AsyncResource` themselves." data-algolia-static="false" data-algolia-merged="false" data-type="Class">class EventEmitterAsyncResourceIntegrates EventEmitter with AsyncResource for EventEmitters that require manual async tracking. Specifically, all events emitted by instances of events.EventEmitterAsyncResource will run within its async context.import { EventEmitterAsyncResource, EventEmitter } from 'node:events'; import { notStrictEqual, strictEqual } from 'node:assert'; import { executionAsyncId, triggerAsyncId } from 'node:async_hooks'; // Async tracking tooling will identify this as 'Q'. const ee1 = new EventEmitterAsyncResource({ name: 'Q' }); // 'foo' listeners will run in the EventEmitters async context. ee1.on('foo', () => { strictEqual(executionAsyncId(), ee1.asyncId); strictEqual(triggerAsyncId(), ee1.triggerAsyncId); }); const ee2 = new EventEmitter(); // 'foo' listeners on ordinary EventEmitters that do not track async // context, however, run in the same async context as the emit(). ee2.on('foo', () => { notStrictEqual(executionAsyncId(), ee2.asyncId); notStrictEqual(triggerAsyncId(), ee2.triggerAsyncId); }); Promise.resolve().then(() => { ee1.emit('foo'); ee2.emit('foo'); }); The EventEmitterAsyncResource class has the same methods and takes the same options as EventEmitter and AsyncResource themselves.readonly asyncId: numberThe unique asyncId assigned to the resource.readonly asyncResource: EventEmitterReferencingAsyncResourceThe returned AsyncResource object has an additional eventEmitter property that provides a reference to this EventEmitterAsyncResource.readonly triggerAsyncId: numberThe same triggerAsyncId that is passed to the AsyncResource constructor.[events.captureRejectionSymbol](error: Error,event: string | symbol,...args: any[]): void;The Symbol.for('nodejs.rejection') method is called in case a promise rejection happens when emitting an event and captureRejections is enabled on the emitter. It is possible to use events.captureRejectionSymbol in place of Symbol.for('nodejs.rejection').import { EventEmitter, captureRejectionSymbol } from 'node:events'; class MyClass extends EventEmitter { constructor() { super({ captureRejections: true }); } [captureRejectionSymbol](err, event, ...args) { console.log('rejection happened for', event, 'with', err, ...args); this.destroy(err); } destroy(err) { // Tear the resource down here. } } addListenerE extends string | symbol>(eventName: string | symbol,listener: (...args: any[]) => void): this;Alias for emitter.on(eventName, listener).emitE extends string | symbol>(eventName: string | symbol,...args: any[]): boolean;Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments to each.Returns true if the event had listeners, false otherwise.import { EventEmitter } from 'node:events'; const myEmitter = new EventEmitter(); // First listener myEmitter.on('event', function firstListener() { console.log('Helloooo! first listener'); }); // Second listener myEmitter.on('event', function secondListener(arg1, arg2) { console.log(`event with parameters ${arg1}, ${arg2} in second listener`); }); // Third listener myEmitter.on('event', function thirdListener(...args) { const parameters = args.join(', '); console.log(`event with parameters ${parameters} in third listener`); }); console.log(myEmitter.listeners('event')); myEmitter.emit('event', 1, 2, 3, 4, 5); // Prints: // [ // [Function: firstListener], // [Function: secondListener], // [Function: thirdListener] // ] // Helloooo! first listener // event with parameters 1, 2 in second listener // event with parameters 1, 2, 3, 4, 5 in third listener emitDestroy(): void;Call all destroy hooks. This should only ever be called once. An error will be thrown if it is called more than once. This must be manually called. If the resource is left to be collected by the GC then the destroy hooks will never be called. {}); myEE.on('bar', () => {}); const sym = Symbol('symbol'); myEE.on(sym, () => {}); console.log(myEE.eventNames()); // Prints: [ 'foo', 'bar', Symbol(symbol) ] ```" data-algolia-static="false" data-algolia-merged="false" data-type="Method">eventNames(): string | symbol[];Returns an array listing the events for which the emitter has registered listeners.import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.on('foo', () => {}); myEE.on('bar', () => {}); const sym = Symbol('symbol'); myEE.on(sym, () => {}); console.log(myEE.eventNames()); // Prints: [ 'foo', 'bar', Symbol(symbol) ] getMaxListeners(): number;Returns the current max listener value for the EventEmitter which is either set by emitter.setMaxListeners(n) or defaults to events.defaultMaxListeners.listenerCountE extends string | symbol>(eventName: string | symbol,listener?: (...args: any[]) => void): number;Returns the number of listeners listening for the event named eventName. If listener is provided, it will return how many times the listener is found in the list of the listeners of the event.@param eventNameThe name of the event being listened for@param listenerThe event handler function { console.log('someone connected!'); }); console.log(util.inspect(server.listeners('connection'))); // Prints: [ [Function] ] ```" data-algolia-static="false" data-algolia-merged="false" data-type="Method">listenersE extends string | symbol>(eventName: string | symbol): (...args: any[]) => void[];Returns a copy of the array of listeners for the event named eventName.server.on('connection', (stream) => { console.log('someone connected!'); }); console.log(util.inspect(server.listeners('connection'))); // Prints: [ [Function] ] offE extends string | symbol>(eventName: string | symbol,listener: (...args: any[]) => void): this;Alias for emitter.removeListener(). { console.log('someone connected!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. By default, event listeners are invoked in the order they are added. The `emitter.prependListener()` method can be used as an alternative to add the event listener to the beginning of the listeners array. ```js import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.on('foo', () => console.log('a')); myEE.prependListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a ```" data-algolia-static="false" data-algolia-merged="false" data-type="Method">onE extends string | symbol>(eventName: string | symbol,listener: (...args: any[]) => void): this;Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.server.on('connection', (stream) => { console.log('someone connected!'); }); Returns a reference to the EventEmitter, so that calls can be chained.By default, event listeners are invoked in the order they are added. The emitter.prependListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.on('foo', () => console.log('a')); myEE.prependListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a @param eventNameThe name of the event.@param listenerThe callback function { console.log('Ah, we have our first user!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. By default, event listeners are invoked in the order they are added. The `emitter.prependOnceListener()` method can be used as an alternative to add the event listener to the beginning of the listeners array. ```js import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.once('foo', () => console.log('a')); myEE.prependOnceListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a ```" data-algolia-static="false" data-algolia-merged="false" data-type="Method">onceE extends string | symbol>(eventName: string | symbol,listener: (...args: any[]) => void): this;Adds a one-time listener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked.server.once('connection', (stream) => { console.log('Ah, we have our first user!'); }); Returns a reference to the EventEmitter, so that calls can be chained.By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.once('foo', () => console.log('a')); myEE.prependOnceListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a @param eventNameThe name of the event.@param listenerThe callback function { console.log('someone connected!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained." data-algolia-static="false" data-algolia-merged="false" data-type="Method">prependListenerE extends string | symbol>(eventName: string | symbol,listener: (...args: any[]) => void): this;Adds the listener function to the beginning of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.server.prependListener('connection', (stream) => { console.log('someone connected!'); }); Returns a reference to the EventEmitter, so that calls can be chained.@param eventNameThe name of the event.@param listenerThe callback function { console.log('Ah, we have our first user!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained." data-algolia-static="false" data-algolia-merged="false" data-type="Method">prependOnceListenerE extends string | symbol>(eventName: string | symbol,listener: (...args: any[]) => void): this;Adds a one-time listener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this listener is removed, and then invoked.server.prependOnceListener('connection', (stream) => { console.log('Ah, we have our first user!'); }); Returns a reference to the EventEmitter, so that calls can be chained.@param eventNameThe name of the event.@param listenerThe callback function console.log('log once')); // Returns a new Array with a function `onceWrapper` which has a property // `listener` which contains the original listener bound above const listeners = emitter.rawListeners('log'); const logFnWrapper = listeners[0]; // Logs "log once" to the console and does not unbind the `once` event logFnWrapper.listener(); // Logs "log once" to the console and removes the listener logFnWrapper(); emitter.on('log', () => console.log('log persistently')); // Will return a new Array with a single function bound by `.on()` above const newListeners = emitter.rawListeners('log'); // Logs "log persistently" twice newListeners[0](); emitter.emit('log'); ```" data-algolia-static="false" data-algolia-merged="false" data-type="Method">rawListenersE extends string | symbol>(eventName: string | symbol): (...args: any[]) => void[];Returns a copy of the array of listeners for the event named eventName, including any wrappers (such as those created by .once()).import { EventEmitter } from 'node:events'; const emitter = new EventEmitter(); emitter.once('log', () => console.log('log once')); // Returns a new Array with a function `onceWrapper` which has a property // `listener` which contains the original listener bound above const listeners = emitter.rawListeners('log'); const logFnWrapper = listeners[0]; // Logs "log once" to the console and does not unbind the `once` event logFnWrapper.listener(); // Logs "log once" to the console and removes the listener logFnWrapper(); emitter.on('log', () => console.log('log persistently')); // Will return a new Array with a single function bound by `.on()` above const newListeners = emitter.rawListeners('log'); // Logs "log persistently" twice newListeners[0](); emitter.emit('log'); removeAllListenersE extends string | symbol>(eventName?: string | symbol): this;Removes all listeners, or those of the specified eventName.It is bad practice to remove listeners added elsewhere in the code, particularly when the EventEmitter instance was created by some other component or module (e.g. sockets or file streams).Returns a reference to the EventEmitter, so that calls can be chained. { console.log('someone connected!'); }; server.on('connection', callback); // ... server.removeListener('connection', callback); ``` `removeListener()` 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 `eventName`, then `removeListener()` must be called multiple times to remove each instance. Once an event is emitted, all listeners attached to it at the time of emitting are called in order. This implies that any `removeListener()` or `removeAllListeners()` calls _after_ emitting and _before_ the last listener finishes execution will not remove them from `emit()` in progress. Subsequent events behave as expected. ```js import { EventEmitter } from 'node:events'; class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); const callbackA = () => { console.log('A'); myEmitter.removeListener('event', callbackB); }; const callbackB = () => { console.log('B'); }; myEmitter.on('event', callbackA); myEmitter.on('event', callbackB); // callbackA removes listener callbackB but it will still be called. // Internal listener array at time of emit [callbackA, callbackB] myEmitter.emit('event'); // Prints: // A // B // callbackB is now removed. // Internal listener array [callbackA] myEmitter.emit('event'); // Prints: // A ``` Because listeners are managed using an internal array, calling this will change the position indexes of any listener registered _after_ 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 `emitter.listeners()` method will need to be recreated. When a single function has been added as a handler multiple times for a single event (as in the example below), `removeListener()` will remove the most recently added instance. In the example the `once('ping')` listener is removed: ```js import { EventEmitter } from 'node:events'; const ee = new EventEmitter(); function pong() { console.log('pong'); } ee.on('ping', pong); ee.once('ping', pong); ee.removeListener('ping', pong); ee.emit('ping'); ee.emit('ping'); ``` Returns a reference to the `EventEmitter`, so that calls can be chained." data-algolia-static="false" data-algolia-merged="false" data-type="Method">removeListenerE extends string | symbol>(eventName: string | symbol,listener: (...args: any[]) => void): this;Removes the specified listener from the listener array for the event named eventName.const callback = (stream) => { console.log('someone connected!'); }; server.on('connection', callback); // ... server.removeListener('connection', callback); removeListener() 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 eventName, then removeListener() must be called multiple times to remove each instance.Once an event is emitted, all listeners attached to it at the time of emitting are called in order. This implies that any removeListener() or removeAllListeners() calls after emitting and before the last listener finishes execution will not remove them from emit() in progress. Subsequent events behave as expected.import { EventEmitter } from 'node:events'; class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); const callbackA = () => { console.log('A'); myEmitter.removeListener('event', callbackB); }; const callbackB = () => { console.log('B'); }; myEmitter.on('event', callbackA); myEmitter.on('event', callbackB); // callbackA removes listener callbackB but it will still be called. // Internal listener array at time of emit [callbackA, callbackB] myEmitter.emit('event'); // Prints: // A // B // callbackB is now removed. // Internal listener array [callbackA] myEmitter.emit('event'); // Prints: // A Because listeners are managed using an internal array, calling this will change the position indexes of any listener registered after 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 emitter.listeners() method will need to be recreated.When a single function has been added as a handler multiple times for a single event (as in the example below), removeListener() will remove the most recently added instance. In the example the once('ping') listener is removed:import { EventEmitter } from 'node:events'; const ee = new EventEmitter(); function pong() { console.log('pong'); } ee.on('ping', pong); ee.once('ping', pong); ee.removeListener('ping', pong); ee.emit('ping'); ee.emit('ping'); Returns a reference to the EventEmitter, so that calls can be chained.setMaxListeners(n: number): this;By default EventEmitters will print a warning if more than 10 listeners are added for a particular event. This is a useful default that helps finding memory leaks. The emitter.setMaxListeners() method allows the limit to be modified for this specific EventEmitter instance. The value can be set to Infinity (or 0) to indicate an unlimited number of listeners.Returns a reference to the EventEmitter, so that calls can be chained.Resources
ReferenceDocsGuidesDiscordMerch StoreGitHubBlogToolkit
RuntimePackage managerTest runnerBundlerPackage runnerProject
Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicenseBaked with ❤️ in San FranciscoWe're hiring →智能索引记录
-
2026-03-02 15:36:37
综合导航
成功
标题:杂志风时尚品牌产品宣传介绍PPT-果果圈模板
简介:杂志风时尚品牌产品宣传介绍PPT主要是为需要进行产品宣传推广的用户制作PPT提供模板,需要的话就来下载吧。
-
2026-03-02 18:44:52
综合导航
成功
标题:梦想屋玩具公司联系方式最新章节_Capter6-坦4第1页_梦想屋玩具公司联系方式免费阅读_恋上你看书网
简介:Capter6-坦4第1页_梦想屋玩具公司联系方式_诗翎_恋上你看书网
-
2026-03-02 16:14:51
综合导航
成功
标题:ISG job portal - Code of Conduct
简介:Code of Conduct. ISG Personalmanagement GmbH commits itself
-
2026-03-02 18:56:50
综合导航
成功
标题:什么是海外虚拟主机-域名店--域名抢注,域名注册,权重域名注册
简介:什么是海外虚拟主机
-
2026-03-02 18:00:25
综合导航
成功
标题:èç®±çæ¼é³_èç®±çææ_èç®±çç¹ä½_è¯ç»ç½
简介:è¯ç»ç½èç®±é¢é,ä»ç»èç®±,èç®±çæ¼é³,èç®±æ¯
-
2026-03-02 15:45:36
综合导航
成功
标题:周易八字起名-八字起名_免费生辰八字起名字-起点起名网
简介:八字起名即传统国学生辰八字起名字,是根据起名人出生时间,出生地点来进行生辰八字五行起名,使名字助运个人八字运势发展。,起
-
2026-03-02 17:40:42
新闻资讯
成功
标题:602《烈火战神》十九服于10月1日13时正式开启! - 新闻公告 - 602游戏平台 - 做玩家喜爱、信任的游戏平台!cccS
简介:602《烈火战神》十九服于10月1日13时正式开启!
-
2026-03-02 17:51:13
综合导航
成功
标题:On the Eve of Convergence: What Happened in 2025 for U.S. Stocks/Tokenization, and Where is the Spark for 2026? Bee Network
简介:The year 2025 has passed in a flash. This year, global finan
-
2026-03-02 17:02:58
综合导航
成功
标题:Warren Tomlin Partner, Digital and Innovation, Ernst & Young LLP EY - MENA
简介:<p>Warren is the leader of the EY-Shopify global alliance. I
-
2026-03-02 18:11:49
综合导航
成功
标题:1x.com • Animals
简介:1x.com is the world
-
2026-03-02 11:34:15
教育培训
成功
标题:公园秋色作文【推荐】
简介:在日常学习、工作或生活中,大家都接触过作文吧,作文要求篇章结构完整,一定要避免无结尾作文的出现。你知道作文怎样写才规范吗
-
2026-03-02 17:43:13
金融理财
成功
标题:26年cfa二级考试时间安排详解!点击查看!-高顿
简介:CFA是全球投资业里较为严格、含金量较高的资格认证,与FRM、CQF并称为美国金融领域的国际三大黄金认证,被全球超过17
-
2026-03-02 10:03:18
教育培训
成功
标题:描写爷爷的作文集合5篇
简介:在平凡的学习、工作、生活中,大家都经常接触到作文吧,作文是人们以书面形式表情达意的言语活动。如何写一篇有思想、有文采的作
-
2026-03-02 17:02:10
综合导航
成功
标题:新润食品招聘_福建省新润食品有限公司招聘_电话_地址 _【官方】
简介:新润食品招聘,福建省新润食品有限公司招聘,公司在福建省漳州市漳浦县长桥镇路美村,招聘岗位详情。
-
2026-03-02 19:14:32
综合导航
成功
标题:LKC Technologies
简介:Industry leaders in Electroretinography (ERG) and visual evo
-
2026-03-02 12:06:22
综合导航
成功
标题:Fluent in AI: Preparing Irish retail for smarter consumers. EY - Ireland
简介:Ireland ranks fourth globally in AI usage, transforming reta
-
2026-03-02 19:11:31
综合导航
成功
标题:寻剑动漫在线观看最新章节_寻剑动漫在线观看全文免费阅读_恋上你看书网
简介:一个有鬼、有妖、有圣灵、有神剑、有门派、有书生、有魁、有侠,却唯独没有帝王与军队的世界,被一个高素质高组织邪恶大军入侵,
-
2026-03-02 09:57:04
教育培训
成功
标题:聪明的小猴作文(精选27篇)
简介:在学习、工作乃至生活中,许多人都有过写作文的经历,对作文都不陌生吧,作文是人们以书面形式表情达意的言语活动。那要怎么写好
-
2026-03-02 19:31:26
综合导航
成功
标题:å
µç»è¯_å
µåç»è¯_è¯ç»ç½
简介:è¯ç»ç½å µç»è¯é¢é,æä¾å ³äºå µç»è¯ç¸å ³è¯è¯,å
-
2026-03-02 17:40:29
综合导航
成功
标题:Anmeldung WTS Newsletter WTS Deutschland
简介:Tax & Finance Newsletter ➥ Newsletter passend zu Ihren Inter
-
2026-03-02 09:07:53
游戏娱乐
成功
标题:炮打彩球,炮打彩球小游戏,4399小游戏 www.4399.com
简介:炮打彩球在线玩,炮打彩球下载, 炮打彩球攻略秘籍.更多炮打彩球游戏尽在4399小游戏,好玩记得告诉你的朋友哦!
-
2026-03-02 16:30:06
综合导航
成功
标题:When the price of Ethereum and its micro-strategies fluctuates drastically, how can we make steady progress in the optio Bee Network
简介:With Ethereum breaking through 4868, it officially reached a
-
2026-03-02 16:05:58
综合导航
成功
标题:脾虚怎么调理 - 云大夫
简介:如脾虚出现倦怠乏力、纳差、腹胀、腹泻、月经量多等临床表现时。治疗上首先可以通过食补进行治疗,如喝稀粥、吃面条山药、大枣等
-
2026-03-02 16:41:47
电商商城
成功
标题:皮雪花牛仔裤怎么样 - 京东
简介:京东是专业的皮雪花牛仔裤网上购物商城,为您提供皮雪花牛仔裤价格图片信息、皮雪花牛仔裤怎么样的用户评论、皮雪花牛仔裤精选导
-
2026-03-02 19:11:26
综合导航
成功
标题:满分恋爱设计图最新章节_第63章第1页_满分恋爱设计图免费章节_恋上你看书网
简介:第63章第1页_满分恋爱设计图_何缺_恋上你看书网
-
2026-03-02 11:32:57
综合导航
成功
标题:AI Strategies AI.4U.com
简介:Be guided by AI.4U.com in becoming a global AI industry lead
-
2026-03-02 06:35:23
教育培训
成功
标题:写景的作文精选(7篇)
简介:在生活、工作和学习中,大家都写过作文吧,作文是从内部言语向外部言语的过渡,即从经过压缩的简要的、自己能明白的语言,向开展
-
2026-03-02 18:15:03
综合导航
成功
标题:员工关键事件评分细则-果果圈模板
简介:员工关键事件评分细则,细则介绍详细严谨,欢迎下载使用。
-
2026-03-02 16:10:02
图片素材
成功
标题:农夫的作文40字 描写农夫的作文 关于农夫的作文-作文网
简介:作文网精选关于农夫的40字作文,包含农夫的作文素材,关于农夫的作文题目,以农夫为话题的40字作文大全,作文网原创名师点评
-
2026-03-02 10:00:44
综合导航
成功
标题:Office Furniture Warehouse Best in Class Office Furniture BOS
简介:Our 260,000+ square feet of climate controlled, on-site offi