diff options
author | Chris Knight <cknight1234@gmail.com> | 2020-02-11 20:55:54 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-11 15:55:54 -0500 |
commit | a7056095a5c9dd000c3c9468d63d695d029969bd (patch) | |
tree | 2097c668773c27bd0a0f207593dce1d415622d85 /std/node/events.ts | |
parent | 92019498f6361c31ad24decfc14e81660959f6cb (diff) |
feat(node): add EventEmitter.errorMonitor (#3960)
Diffstat (limited to 'std/node/events.ts')
-rw-r--r-- | std/node/events.ts | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/std/node/events.ts b/std/node/events.ts index a085ff86b..92fe7a704 100644 --- a/std/node/events.ts +++ b/std/node/events.ts @@ -32,6 +32,7 @@ export interface WrappedFunction extends Function { */ export default class EventEmitter { public static defaultMaxListeners = 10; + public static errorMonitor = Symbol("events.errorMonitor"); private maxListeners: number | undefined; private _events: Map<string | symbol, Array<Function | WrappedFunction>>; @@ -88,6 +89,12 @@ export default class EventEmitter { // eslint-disable-next-line @typescript-eslint/no-explicit-any public emit(eventName: string | symbol, ...args: any[]): boolean { if (this._events.has(eventName)) { + if ( + eventName === "error" && + this._events.get(EventEmitter.errorMonitor) + ) { + this.emit(EventEmitter.errorMonitor, ...args); + } const listeners = (this._events.get(eventName) as Function[]).slice(); // We copy with slice() so array is not mutated during emit for (const listener of listeners) { try { @@ -98,6 +105,9 @@ export default class EventEmitter { } return true; } else if (eventName === "error") { + if (this._events.get(EventEmitter.errorMonitor)) { + this.emit(EventEmitter.errorMonitor, ...args); + } const errMsg = args.length > 0 ? args[0] : Error("Unhandled error."); throw errMsg; } |