1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const events_1 = require("events");
|
4 | class EventEmitter extends events_1.EventEmitter {
|
5 | on(event, listener) {
|
6 | this.ensureListenerCount(event, (maxListeners) => maxListeners + 1);
|
7 | return super.on(event, listener);
|
8 | }
|
9 | off(event, listener) {
|
10 | return this.removeListener(event, listener);
|
11 | }
|
12 | once(event, listener) {
|
13 | this.ensureListenerCount(event, (maxListeners) => maxListeners + 1);
|
14 | return super.once(event, listener);
|
15 | }
|
16 | addListener(event, listener) {
|
17 | return this.on(event, listener);
|
18 | }
|
19 | removeListener(event, listener) {
|
20 | this.ensureListenerCount(event, (maxListeners) => maxListeners - 1);
|
21 | return super.removeListener(event, listener);
|
22 | }
|
23 | ensureListenerCount(event, count) {
|
24 | const maxListeners = this.getMaxListeners();
|
25 | const listenerCount = this.listenerCount(event);
|
26 | if (listenerCount >= maxListeners) {
|
27 | this.setMaxListeners(count(maxListeners));
|
28 | }
|
29 | }
|
30 | }
|
31 | exports.EventEmitter = EventEmitter;
|
32 |
|
\ | No newline at end of file |