rahad-all-downloader 2.1.16 → 2.1.17
Sign up to get free protection for your applications and to get access to all the features.
- package/.github/workflows/Run.yml +20 -0
- package/README.md +0 -1
- package/index.js +1 -1
- package/package.json +4 -2
- package/.cache/nix/binary-cache-v6.sqlite +0 -0
- package/.cache/nix/binary-cache-v6.sqlite-journal +0 -0
- package/.cache/replit/env/latest +0 -123
- package/.cache/replit/env/latest.json +0 -1
- package/.cache/replit/modules/nix.res +0 -1
- package/.cache/replit/modules/nodejs-20.res +0 -1
- package/.cache/replit/modules/replit.res +0 -1
- package/.cache/replit/modules.stamp +0 -0
- package/.cache/replit/nix/env.json +0 -1
- package/.cache/typescript/5.4/node_modules/.package-lock.json +0 -137
- package/.cache/typescript/5.4/node_modules/@types/caseless/LICENSE +0 -21
- package/.cache/typescript/5.4/node_modules/@types/caseless/README.md +0 -48
- package/.cache/typescript/5.4/node_modules/@types/caseless/index.d.ts +0 -29
- package/.cache/typescript/5.4/node_modules/@types/caseless/package.json +0 -35
- package/.cache/typescript/5.4/node_modules/@types/node/LICENSE +0 -21
- package/.cache/typescript/5.4/node_modules/@types/node/README.md +0 -15
- package/.cache/typescript/5.4/node_modules/@types/node/assert/strict.d.ts +0 -8
- package/.cache/typescript/5.4/node_modules/@types/node/assert.d.ts +0 -1040
- package/.cache/typescript/5.4/node_modules/@types/node/async_hooks.d.ts +0 -541
- package/.cache/typescript/5.4/node_modules/@types/node/buffer.d.ts +0 -2363
- package/.cache/typescript/5.4/node_modules/@types/node/child_process.d.ts +0 -1544
- package/.cache/typescript/5.4/node_modules/@types/node/cluster.d.ts +0 -578
- package/.cache/typescript/5.4/node_modules/@types/node/console.d.ts +0 -452
- package/.cache/typescript/5.4/node_modules/@types/node/constants.d.ts +0 -19
- package/.cache/typescript/5.4/node_modules/@types/node/crypto.d.ts +0 -4523
- package/.cache/typescript/5.4/node_modules/@types/node/dgram.d.ts +0 -596
- package/.cache/typescript/5.4/node_modules/@types/node/diagnostics_channel.d.ts +0 -554
- package/.cache/typescript/5.4/node_modules/@types/node/dns/promises.d.ts +0 -474
- package/.cache/typescript/5.4/node_modules/@types/node/dns.d.ts +0 -864
- package/.cache/typescript/5.4/node_modules/@types/node/dom-events.d.ts +0 -124
- package/.cache/typescript/5.4/node_modules/@types/node/domain.d.ts +0 -170
- package/.cache/typescript/5.4/node_modules/@types/node/events.d.ts +0 -909
- package/.cache/typescript/5.4/node_modules/@types/node/fs/promises.d.ts +0 -1245
- package/.cache/typescript/5.4/node_modules/@types/node/fs.d.ts +0 -4317
- package/.cache/typescript/5.4/node_modules/@types/node/globals.d.ts +0 -411
- package/.cache/typescript/5.4/node_modules/@types/node/globals.global.d.ts +0 -1
- package/.cache/typescript/5.4/node_modules/@types/node/http.d.ts +0 -1908
- package/.cache/typescript/5.4/node_modules/@types/node/http2.d.ts +0 -2418
- package/.cache/typescript/5.4/node_modules/@types/node/https.d.ts +0 -550
- package/.cache/typescript/5.4/node_modules/@types/node/index.d.ts +0 -89
- package/.cache/typescript/5.4/node_modules/@types/node/inspector.d.ts +0 -2746
- package/.cache/typescript/5.4/node_modules/@types/node/module.d.ts +0 -315
- package/.cache/typescript/5.4/node_modules/@types/node/net.d.ts +0 -999
- package/.cache/typescript/5.4/node_modules/@types/node/os.d.ts +0 -495
- package/.cache/typescript/5.4/node_modules/@types/node/package.json +0 -217
- package/.cache/typescript/5.4/node_modules/@types/node/path.d.ts +0 -191
- package/.cache/typescript/5.4/node_modules/@types/node/perf_hooks.d.ts +0 -905
- package/.cache/typescript/5.4/node_modules/@types/node/process.d.ts +0 -1754
- package/.cache/typescript/5.4/node_modules/@types/node/punycode.d.ts +0 -117
- package/.cache/typescript/5.4/node_modules/@types/node/querystring.d.ts +0 -153
- package/.cache/typescript/5.4/node_modules/@types/node/readline/promises.d.ts +0 -150
- package/.cache/typescript/5.4/node_modules/@types/node/readline.d.ts +0 -540
- package/.cache/typescript/5.4/node_modules/@types/node/repl.d.ts +0 -430
- package/.cache/typescript/5.4/node_modules/@types/node/sea.d.ts +0 -153
- package/.cache/typescript/5.4/node_modules/@types/node/stream/consumers.d.ts +0 -12
- package/.cache/typescript/5.4/node_modules/@types/node/stream/promises.d.ts +0 -83
- package/.cache/typescript/5.4/node_modules/@types/node/stream/web.d.ts +0 -367
- package/.cache/typescript/5.4/node_modules/@types/node/stream.d.ts +0 -1707
- package/.cache/typescript/5.4/node_modules/@types/node/string_decoder.d.ts +0 -67
- package/.cache/typescript/5.4/node_modules/@types/node/test.d.ts +0 -1718
- package/.cache/typescript/5.4/node_modules/@types/node/timers/promises.d.ts +0 -97
- package/.cache/typescript/5.4/node_modules/@types/node/timers.d.ts +0 -240
- package/.cache/typescript/5.4/node_modules/@types/node/tls.d.ts +0 -1217
- package/.cache/typescript/5.4/node_modules/@types/node/trace_events.d.ts +0 -197
- package/.cache/typescript/5.4/node_modules/@types/node/tty.d.ts +0 -208
- package/.cache/typescript/5.4/node_modules/@types/node/url.d.ts +0 -952
- package/.cache/typescript/5.4/node_modules/@types/node/util.d.ts +0 -2292
- package/.cache/typescript/5.4/node_modules/@types/node/v8.d.ts +0 -808
- package/.cache/typescript/5.4/node_modules/@types/node/vm.d.ts +0 -924
- package/.cache/typescript/5.4/node_modules/@types/node/wasi.d.ts +0 -181
- package/.cache/typescript/5.4/node_modules/@types/node/worker_threads.d.ts +0 -691
- package/.cache/typescript/5.4/node_modules/@types/node/zlib.d.ts +0 -530
- package/.cache/typescript/5.4/node_modules/@types/node-fetch/LICENSE +0 -21
- package/.cache/typescript/5.4/node_modules/@types/node-fetch/README.md +0 -15
- package/.cache/typescript/5.4/node_modules/@types/node-fetch/externals.d.ts +0 -32
- package/.cache/typescript/5.4/node_modules/@types/node-fetch/index.d.ts +0 -238
- package/.cache/typescript/5.4/node_modules/@types/node-fetch/package.json +0 -83
- package/.cache/typescript/5.4/node_modules/@types/request/LICENSE +0 -21
- package/.cache/typescript/5.4/node_modules/@types/request/README.md +0 -15
- package/.cache/typescript/5.4/node_modules/@types/request/index.d.ts +0 -395
- package/.cache/typescript/5.4/node_modules/@types/request/node_modules/form-data/License +0 -19
- package/.cache/typescript/5.4/node_modules/@types/request/node_modules/form-data/README.md +0 -350
- package/.cache/typescript/5.4/node_modules/@types/request/node_modules/form-data/README.md.bak +0 -350
- package/.cache/typescript/5.4/node_modules/@types/request/node_modules/form-data/index.d.ts +0 -51
- package/.cache/typescript/5.4/node_modules/@types/request/node_modules/form-data/lib/browser.js +0 -2
- package/.cache/typescript/5.4/node_modules/@types/request/node_modules/form-data/lib/form_data.js +0 -483
- package/.cache/typescript/5.4/node_modules/@types/request/node_modules/form-data/lib/populate.js +0 -10
- package/.cache/typescript/5.4/node_modules/@types/request/node_modules/form-data/package.json +0 -68
- package/.cache/typescript/5.4/node_modules/@types/request/package.json +0 -70
- package/.cache/typescript/5.4/node_modules/@types/tough-cookie/LICENSE +0 -21
- package/.cache/typescript/5.4/node_modules/@types/tough-cookie/README.md +0 -15
- package/.cache/typescript/5.4/node_modules/@types/tough-cookie/index.d.ts +0 -321
- package/.cache/typescript/5.4/node_modules/@types/tough-cookie/package.json +0 -35
- package/.cache/typescript/5.4/node_modules/asynckit/LICENSE +0 -21
- package/.cache/typescript/5.4/node_modules/asynckit/README.md +0 -233
- package/.cache/typescript/5.4/node_modules/asynckit/bench.js +0 -76
- package/.cache/typescript/5.4/node_modules/asynckit/index.js +0 -6
- package/.cache/typescript/5.4/node_modules/asynckit/lib/abort.js +0 -29
- package/.cache/typescript/5.4/node_modules/asynckit/lib/async.js +0 -34
- package/.cache/typescript/5.4/node_modules/asynckit/lib/defer.js +0 -26
- package/.cache/typescript/5.4/node_modules/asynckit/lib/iterate.js +0 -75
- package/.cache/typescript/5.4/node_modules/asynckit/lib/readable_asynckit.js +0 -91
- package/.cache/typescript/5.4/node_modules/asynckit/lib/readable_parallel.js +0 -25
- package/.cache/typescript/5.4/node_modules/asynckit/lib/readable_serial.js +0 -25
- package/.cache/typescript/5.4/node_modules/asynckit/lib/readable_serial_ordered.js +0 -29
- package/.cache/typescript/5.4/node_modules/asynckit/lib/state.js +0 -37
- package/.cache/typescript/5.4/node_modules/asynckit/lib/streamify.js +0 -141
- package/.cache/typescript/5.4/node_modules/asynckit/lib/terminator.js +0 -29
- package/.cache/typescript/5.4/node_modules/asynckit/package.json +0 -63
- package/.cache/typescript/5.4/node_modules/asynckit/parallel.js +0 -43
- package/.cache/typescript/5.4/node_modules/asynckit/serial.js +0 -17
- package/.cache/typescript/5.4/node_modules/asynckit/serialOrdered.js +0 -75
- package/.cache/typescript/5.4/node_modules/asynckit/stream.js +0 -21
- package/.cache/typescript/5.4/node_modules/combined-stream/License +0 -19
- package/.cache/typescript/5.4/node_modules/combined-stream/Readme.md +0 -138
- package/.cache/typescript/5.4/node_modules/combined-stream/lib/combined_stream.js +0 -208
- package/.cache/typescript/5.4/node_modules/combined-stream/package.json +0 -25
- package/.cache/typescript/5.4/node_modules/combined-stream/yarn.lock +0 -17
- package/.cache/typescript/5.4/node_modules/delayed-stream/License +0 -19
- package/.cache/typescript/5.4/node_modules/delayed-stream/Makefile +0 -7
- package/.cache/typescript/5.4/node_modules/delayed-stream/Readme.md +0 -141
- package/.cache/typescript/5.4/node_modules/delayed-stream/lib/delayed_stream.js +0 -107
- package/.cache/typescript/5.4/node_modules/delayed-stream/package.json +0 -27
- package/.cache/typescript/5.4/node_modules/form-data/License +0 -19
- package/.cache/typescript/5.4/node_modules/form-data/README.md.bak +0 -358
- package/.cache/typescript/5.4/node_modules/form-data/Readme.md +0 -358
- package/.cache/typescript/5.4/node_modules/form-data/index.d.ts +0 -62
- package/.cache/typescript/5.4/node_modules/form-data/lib/browser.js +0 -2
- package/.cache/typescript/5.4/node_modules/form-data/lib/form_data.js +0 -501
- package/.cache/typescript/5.4/node_modules/form-data/lib/populate.js +0 -10
- package/.cache/typescript/5.4/node_modules/form-data/package.json +0 -68
- package/.cache/typescript/5.4/node_modules/mime-db/HISTORY.md +0 -507
- package/.cache/typescript/5.4/node_modules/mime-db/LICENSE +0 -23
- package/.cache/typescript/5.4/node_modules/mime-db/README.md +0 -100
- package/.cache/typescript/5.4/node_modules/mime-db/db.json +0 -8519
- package/.cache/typescript/5.4/node_modules/mime-db/index.js +0 -12
- package/.cache/typescript/5.4/node_modules/mime-db/package.json +0 -60
- package/.cache/typescript/5.4/node_modules/mime-types/HISTORY.md +0 -397
- package/.cache/typescript/5.4/node_modules/mime-types/LICENSE +0 -23
- package/.cache/typescript/5.4/node_modules/mime-types/README.md +0 -113
- package/.cache/typescript/5.4/node_modules/mime-types/index.js +0 -188
- package/.cache/typescript/5.4/node_modules/mime-types/package.json +0 -44
- package/.cache/typescript/5.4/node_modules/types-registry/README.md +0 -2
- package/.cache/typescript/5.4/node_modules/types-registry/index.json +0 -1
- package/.cache/typescript/5.4/node_modules/types-registry/package.json +0 -20
- package/.cache/typescript/5.4/node_modules/undici-types/README.md +0 -6
- package/.cache/typescript/5.4/node_modules/undici-types/agent.d.ts +0 -31
- package/.cache/typescript/5.4/node_modules/undici-types/api.d.ts +0 -43
- package/.cache/typescript/5.4/node_modules/undici-types/balanced-pool.d.ts +0 -18
- package/.cache/typescript/5.4/node_modules/undici-types/cache.d.ts +0 -36
- package/.cache/typescript/5.4/node_modules/undici-types/client.d.ts +0 -97
- package/.cache/typescript/5.4/node_modules/undici-types/connector.d.ts +0 -34
- package/.cache/typescript/5.4/node_modules/undici-types/content-type.d.ts +0 -21
- package/.cache/typescript/5.4/node_modules/undici-types/cookies.d.ts +0 -28
- package/.cache/typescript/5.4/node_modules/undici-types/diagnostics-channel.d.ts +0 -67
- package/.cache/typescript/5.4/node_modules/undici-types/dispatcher.d.ts +0 -241
- package/.cache/typescript/5.4/node_modules/undici-types/errors.d.ts +0 -128
- package/.cache/typescript/5.4/node_modules/undici-types/fetch.d.ts +0 -209
- package/.cache/typescript/5.4/node_modules/undici-types/file.d.ts +0 -39
- package/.cache/typescript/5.4/node_modules/undici-types/filereader.d.ts +0 -54
- package/.cache/typescript/5.4/node_modules/undici-types/formdata.d.ts +0 -108
- package/.cache/typescript/5.4/node_modules/undici-types/global-dispatcher.d.ts +0 -9
- package/.cache/typescript/5.4/node_modules/undici-types/global-origin.d.ts +0 -7
- package/.cache/typescript/5.4/node_modules/undici-types/handlers.d.ts +0 -9
- package/.cache/typescript/5.4/node_modules/undici-types/header.d.ts +0 -4
- package/.cache/typescript/5.4/node_modules/undici-types/index.d.ts +0 -63
- package/.cache/typescript/5.4/node_modules/undici-types/interceptors.d.ts +0 -5
- package/.cache/typescript/5.4/node_modules/undici-types/mock-agent.d.ts +0 -50
- package/.cache/typescript/5.4/node_modules/undici-types/mock-client.d.ts +0 -25
- package/.cache/typescript/5.4/node_modules/undici-types/mock-errors.d.ts +0 -12
- package/.cache/typescript/5.4/node_modules/undici-types/mock-interceptor.d.ts +0 -93
- package/.cache/typescript/5.4/node_modules/undici-types/mock-pool.d.ts +0 -25
- package/.cache/typescript/5.4/node_modules/undici-types/package.json +0 -55
- package/.cache/typescript/5.4/node_modules/undici-types/patch.d.ts +0 -71
- package/.cache/typescript/5.4/node_modules/undici-types/pool-stats.d.ts +0 -19
- package/.cache/typescript/5.4/node_modules/undici-types/pool.d.ts +0 -28
- package/.cache/typescript/5.4/node_modules/undici-types/proxy-agent.d.ts +0 -30
- package/.cache/typescript/5.4/node_modules/undici-types/readable.d.ts +0 -61
- package/.cache/typescript/5.4/node_modules/undici-types/webidl.d.ts +0 -220
- package/.cache/typescript/5.4/node_modules/undici-types/websocket.d.ts +0 -131
- package/.cache/typescript/5.4/package-lock.json +0 -146
- package/.cache/typescript/5.4/package.json +0 -1
- package/.replit +0 -21
- package/replit.nix +0 -3
@@ -1,909 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Much of the Node.js core API is built around an idiomatic asynchronous
|
3
|
-
* event-driven architecture in which certain kinds of objects (called "emitters")
|
4
|
-
* emit named events that cause `Function` objects ("listeners") to be called.
|
5
|
-
*
|
6
|
-
* For instance: a `net.Server` object emits an event each time a peer
|
7
|
-
* connects to it; a `fs.ReadStream` emits an event when the file is opened;
|
8
|
-
* a `stream` emits an event whenever data is available to be read.
|
9
|
-
*
|
10
|
-
* All objects that emit events are instances of the `EventEmitter` class. These
|
11
|
-
* objects expose an `eventEmitter.on()` function that allows one or more
|
12
|
-
* functions to be attached to named events emitted by the object. Typically,
|
13
|
-
* event names are camel-cased strings but any valid JavaScript property key
|
14
|
-
* can be used.
|
15
|
-
*
|
16
|
-
* When the `EventEmitter` object emits an event, all of the functions attached
|
17
|
-
* to that specific event are called _synchronously_. Any values returned by the
|
18
|
-
* called listeners are _ignored_ and discarded.
|
19
|
-
*
|
20
|
-
* The following example shows a simple `EventEmitter` instance with a single
|
21
|
-
* listener. The `eventEmitter.on()` method is used to register listeners, while
|
22
|
-
* the `eventEmitter.emit()` method is used to trigger the event.
|
23
|
-
*
|
24
|
-
* ```js
|
25
|
-
* import { EventEmitter } from 'node:events';
|
26
|
-
*
|
27
|
-
* class MyEmitter extends EventEmitter {}
|
28
|
-
*
|
29
|
-
* const myEmitter = new MyEmitter();
|
30
|
-
* myEmitter.on('event', () => {
|
31
|
-
* console.log('an event occurred!');
|
32
|
-
* });
|
33
|
-
* myEmitter.emit('event');
|
34
|
-
* ```
|
35
|
-
* @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/events.js)
|
36
|
-
*/
|
37
|
-
declare module "events" {
|
38
|
-
import { AsyncResource, AsyncResourceOptions } from "node:async_hooks";
|
39
|
-
// NOTE: This class is in the docs but is **not actually exported** by Node.
|
40
|
-
// If https://github.com/nodejs/node/issues/39903 gets resolved and Node
|
41
|
-
// actually starts exporting the class, uncomment below.
|
42
|
-
// import { EventListener, EventListenerObject } from '__dom-events';
|
43
|
-
// /** The NodeEventTarget is a Node.js-specific extension to EventTarget that emulates a subset of the EventEmitter API. */
|
44
|
-
// interface NodeEventTarget extends EventTarget {
|
45
|
-
// /**
|
46
|
-
// * Node.js-specific extension to the `EventTarget` class that emulates the equivalent `EventEmitter` API.
|
47
|
-
// * The only difference between `addListener()` and `addEventListener()` is that addListener() will return a reference to the EventTarget.
|
48
|
-
// */
|
49
|
-
// addListener(type: string, listener: EventListener | EventListenerObject, options?: { once: boolean }): this;
|
50
|
-
// /** Node.js-specific extension to the `EventTarget` class that returns an array of event `type` names for which event listeners are registered. */
|
51
|
-
// eventNames(): string[];
|
52
|
-
// /** Node.js-specific extension to the `EventTarget` class that returns the number of event listeners registered for the `type`. */
|
53
|
-
// listenerCount(type: string): number;
|
54
|
-
// /** Node.js-specific alias for `eventTarget.removeListener()`. */
|
55
|
-
// off(type: string, listener: EventListener | EventListenerObject): this;
|
56
|
-
// /** Node.js-specific alias for `eventTarget.addListener()`. */
|
57
|
-
// on(type: string, listener: EventListener | EventListenerObject, options?: { once: boolean }): this;
|
58
|
-
// /** Node.js-specific extension to the `EventTarget` class that adds a `once` listener for the given event `type`. This is equivalent to calling `on` with the `once` option set to `true`. */
|
59
|
-
// once(type: string, listener: EventListener | EventListenerObject): this;
|
60
|
-
// /**
|
61
|
-
// * Node.js-specific extension to the `EventTarget` class.
|
62
|
-
// * If `type` is specified, removes all registered listeners for `type`,
|
63
|
-
// * otherwise removes all registered listeners.
|
64
|
-
// */
|
65
|
-
// removeAllListeners(type: string): this;
|
66
|
-
// /**
|
67
|
-
// * Node.js-specific extension to the `EventTarget` class that removes the listener for the given `type`.
|
68
|
-
// * The only difference between `removeListener()` and `removeEventListener()` is that `removeListener()` will return a reference to the `EventTarget`.
|
69
|
-
// */
|
70
|
-
// removeListener(type: string, listener: EventListener | EventListenerObject): this;
|
71
|
-
// }
|
72
|
-
interface EventEmitterOptions {
|
73
|
-
/**
|
74
|
-
* Enables automatic capturing of promise rejection.
|
75
|
-
*/
|
76
|
-
captureRejections?: boolean | undefined;
|
77
|
-
}
|
78
|
-
interface StaticEventEmitterOptions {
|
79
|
-
/**
|
80
|
-
* Can be used to cancel awaiting events.
|
81
|
-
*/
|
82
|
-
signal?: AbortSignal | undefined;
|
83
|
-
/**
|
84
|
-
* Names of events that will end the iteration.
|
85
|
-
*/
|
86
|
-
close?: string[] | undefined;
|
87
|
-
/**
|
88
|
-
* The high watermark. The emitter is paused every time the size
|
89
|
-
* of events being buffered is higher than it. Supported only
|
90
|
-
* on emitters implementing `pause()` and `resume()` methods.
|
91
|
-
* @default `Number.MAX_SAFE_INTEGER`
|
92
|
-
*/
|
93
|
-
highWaterMark?: number | undefined;
|
94
|
-
/**
|
95
|
-
* The low watermark. The emitter is resumed every time the size of events being buffered
|
96
|
-
* is lower than it. Supported only on emitters implementing `pause()` and `resume()` methods.
|
97
|
-
* @default 1
|
98
|
-
*/
|
99
|
-
lowWaterMark?: number | undefined;
|
100
|
-
}
|
101
|
-
interface EventEmitter<T extends EventMap<T> = DefaultEventMap> extends NodeJS.EventEmitter<T> {}
|
102
|
-
type EventMap<T> = Record<keyof T, any[]> | DefaultEventMap;
|
103
|
-
type DefaultEventMap = [never];
|
104
|
-
type AnyRest = [...args: any[]];
|
105
|
-
type Args<K, T> = T extends DefaultEventMap ? AnyRest : (
|
106
|
-
K extends keyof T ? T[K] : never
|
107
|
-
);
|
108
|
-
type Key<K, T> = T extends DefaultEventMap ? string | symbol : K | keyof T;
|
109
|
-
type Key2<K, T> = T extends DefaultEventMap ? string | symbol : K & keyof T;
|
110
|
-
type Listener<K, T, F> = T extends DefaultEventMap ? F : (
|
111
|
-
K extends keyof T ? (
|
112
|
-
T[K] extends unknown[] ? (...args: T[K]) => void : never
|
113
|
-
)
|
114
|
-
: never
|
115
|
-
);
|
116
|
-
type Listener1<K, T> = Listener<K, T, (...args: any[]) => void>;
|
117
|
-
type Listener2<K, T> = Listener<K, T, Function>;
|
118
|
-
|
119
|
-
/**
|
120
|
-
* The `EventEmitter` class is defined and exposed by the `node:events` module:
|
121
|
-
*
|
122
|
-
* ```js
|
123
|
-
* import { EventEmitter } from 'node:events';
|
124
|
-
* ```
|
125
|
-
*
|
126
|
-
* All `EventEmitter`s emit the event `'newListener'` when new listeners are
|
127
|
-
* added and `'removeListener'` when existing listeners are removed.
|
128
|
-
*
|
129
|
-
* It supports the following option:
|
130
|
-
* @since v0.1.26
|
131
|
-
*/
|
132
|
-
class EventEmitter<T extends EventMap<T> = DefaultEventMap> {
|
133
|
-
constructor(options?: EventEmitterOptions);
|
134
|
-
|
135
|
-
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: Key<K, T>, ...args: Args<K, T>): void;
|
136
|
-
|
137
|
-
/**
|
138
|
-
* Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given
|
139
|
-
* event or that is rejected if the `EventEmitter` emits `'error'` while waiting.
|
140
|
-
* The `Promise` will resolve with an array of all the arguments emitted to the
|
141
|
-
* given event.
|
142
|
-
*
|
143
|
-
* This method is intentionally generic and works with the web platform [EventTarget](https://dom.spec.whatwg.org/#interface-eventtarget) interface, which has no special`'error'` event
|
144
|
-
* semantics and does not listen to the `'error'` event.
|
145
|
-
*
|
146
|
-
* ```js
|
147
|
-
* import { once, EventEmitter } from 'node:events';
|
148
|
-
* import process from 'node:process';
|
149
|
-
*
|
150
|
-
* const ee = new EventEmitter();
|
151
|
-
*
|
152
|
-
* process.nextTick(() => {
|
153
|
-
* ee.emit('myevent', 42);
|
154
|
-
* });
|
155
|
-
*
|
156
|
-
* const [value] = await once(ee, 'myevent');
|
157
|
-
* console.log(value);
|
158
|
-
*
|
159
|
-
* const err = new Error('kaboom');
|
160
|
-
* process.nextTick(() => {
|
161
|
-
* ee.emit('error', err);
|
162
|
-
* });
|
163
|
-
*
|
164
|
-
* try {
|
165
|
-
* await once(ee, 'myevent');
|
166
|
-
* } catch (err) {
|
167
|
-
* console.error('error happened', err);
|
168
|
-
* }
|
169
|
-
* ```
|
170
|
-
*
|
171
|
-
* The special handling of the `'error'` event is only used when `events.once()` is used to wait for another event. If `events.once()` is used to wait for the
|
172
|
-
* '`error'` event itself, then it is treated as any other kind of event without
|
173
|
-
* special handling:
|
174
|
-
*
|
175
|
-
* ```js
|
176
|
-
* import { EventEmitter, once } from 'node:events';
|
177
|
-
*
|
178
|
-
* const ee = new EventEmitter();
|
179
|
-
*
|
180
|
-
* once(ee, 'error')
|
181
|
-
* .then(([err]) => console.log('ok', err.message))
|
182
|
-
* .catch((err) => console.error('error', err.message));
|
183
|
-
*
|
184
|
-
* ee.emit('error', new Error('boom'));
|
185
|
-
*
|
186
|
-
* // Prints: ok boom
|
187
|
-
* ```
|
188
|
-
*
|
189
|
-
* An `AbortSignal` can be used to cancel waiting for the event:
|
190
|
-
*
|
191
|
-
* ```js
|
192
|
-
* import { EventEmitter, once } from 'node:events';
|
193
|
-
*
|
194
|
-
* const ee = new EventEmitter();
|
195
|
-
* const ac = new AbortController();
|
196
|
-
*
|
197
|
-
* async function foo(emitter, event, signal) {
|
198
|
-
* try {
|
199
|
-
* await once(emitter, event, { signal });
|
200
|
-
* console.log('event emitted!');
|
201
|
-
* } catch (error) {
|
202
|
-
* if (error.name === 'AbortError') {
|
203
|
-
* console.error('Waiting for the event was canceled!');
|
204
|
-
* } else {
|
205
|
-
* console.error('There was an error', error.message);
|
206
|
-
* }
|
207
|
-
* }
|
208
|
-
* }
|
209
|
-
*
|
210
|
-
* foo(ee, 'foo', ac.signal);
|
211
|
-
* ac.abort(); // Abort waiting for the event
|
212
|
-
* ee.emit('foo'); // Prints: Waiting for the event was canceled!
|
213
|
-
* ```
|
214
|
-
* @since v11.13.0, v10.16.0
|
215
|
-
*/
|
216
|
-
static once(
|
217
|
-
emitter: NodeJS.EventEmitter,
|
218
|
-
eventName: string | symbol,
|
219
|
-
options?: Pick<StaticEventEmitterOptions, "signal">,
|
220
|
-
): Promise<any[]>;
|
221
|
-
static once(emitter: EventTarget, eventName: string, options?: StaticEventEmitterOptions): Promise<any[]>;
|
222
|
-
/**
|
223
|
-
* ```js
|
224
|
-
* import { on, EventEmitter } from 'node:events';
|
225
|
-
* import process from 'node:process';
|
226
|
-
*
|
227
|
-
* const ee = new EventEmitter();
|
228
|
-
*
|
229
|
-
* // Emit later on
|
230
|
-
* process.nextTick(() => {
|
231
|
-
* ee.emit('foo', 'bar');
|
232
|
-
* ee.emit('foo', 42);
|
233
|
-
* });
|
234
|
-
*
|
235
|
-
* for await (const event of on(ee, 'foo')) {
|
236
|
-
* // The execution of this inner block is synchronous and it
|
237
|
-
* // processes one event at a time (even with await). Do not use
|
238
|
-
* // if concurrent execution is required.
|
239
|
-
* console.log(event); // prints ['bar'] [42]
|
240
|
-
* }
|
241
|
-
* // Unreachable here
|
242
|
-
* ```
|
243
|
-
*
|
244
|
-
* Returns an `AsyncIterator` that iterates `eventName` events. It will throw
|
245
|
-
* if the `EventEmitter` emits `'error'`. It removes all listeners when
|
246
|
-
* exiting the loop. The `value` returned by each iteration is an array
|
247
|
-
* composed of the emitted event arguments.
|
248
|
-
*
|
249
|
-
* An `AbortSignal` can be used to cancel waiting on events:
|
250
|
-
*
|
251
|
-
* ```js
|
252
|
-
* import { on, EventEmitter } from 'node:events';
|
253
|
-
* import process from 'node:process';
|
254
|
-
*
|
255
|
-
* const ac = new AbortController();
|
256
|
-
*
|
257
|
-
* (async () => {
|
258
|
-
* const ee = new EventEmitter();
|
259
|
-
*
|
260
|
-
* // Emit later on
|
261
|
-
* process.nextTick(() => {
|
262
|
-
* ee.emit('foo', 'bar');
|
263
|
-
* ee.emit('foo', 42);
|
264
|
-
* });
|
265
|
-
*
|
266
|
-
* for await (const event of on(ee, 'foo', { signal: ac.signal })) {
|
267
|
-
* // The execution of this inner block is synchronous and it
|
268
|
-
* // processes one event at a time (even with await). Do not use
|
269
|
-
* // if concurrent execution is required.
|
270
|
-
* console.log(event); // prints ['bar'] [42]
|
271
|
-
* }
|
272
|
-
* // Unreachable here
|
273
|
-
* })();
|
274
|
-
*
|
275
|
-
* process.nextTick(() => ac.abort());
|
276
|
-
* ```
|
277
|
-
* @since v13.6.0, v12.16.0
|
278
|
-
* @param eventName The name of the event being listened for
|
279
|
-
* @return An `AsyncIterator` that iterates `eventName` events emitted by the `emitter`
|
280
|
-
*/
|
281
|
-
static on(
|
282
|
-
emitter: NodeJS.EventEmitter,
|
283
|
-
eventName: string | symbol,
|
284
|
-
options?: StaticEventEmitterOptions,
|
285
|
-
): AsyncIterableIterator<any>;
|
286
|
-
static on(
|
287
|
-
emitter: EventTarget,
|
288
|
-
eventName: string,
|
289
|
-
options?: StaticEventEmitterOptions,
|
290
|
-
): AsyncIterableIterator<any>;
|
291
|
-
/**
|
292
|
-
* A class method that returns the number of listeners for the given `eventName` registered on the given `emitter`.
|
293
|
-
*
|
294
|
-
* ```js
|
295
|
-
* import { EventEmitter, listenerCount } from 'node:events';
|
296
|
-
*
|
297
|
-
* const myEmitter = new EventEmitter();
|
298
|
-
* myEmitter.on('event', () => {});
|
299
|
-
* myEmitter.on('event', () => {});
|
300
|
-
* console.log(listenerCount(myEmitter, 'event'));
|
301
|
-
* // Prints: 2
|
302
|
-
* ```
|
303
|
-
* @since v0.9.12
|
304
|
-
* @deprecated Since v3.2.0 - Use `listenerCount` instead.
|
305
|
-
* @param emitter The emitter to query
|
306
|
-
* @param eventName The event name
|
307
|
-
*/
|
308
|
-
static listenerCount(emitter: NodeJS.EventEmitter, eventName: string | symbol): number;
|
309
|
-
/**
|
310
|
-
* Returns a copy of the array of listeners for the event named `eventName`.
|
311
|
-
*
|
312
|
-
* For `EventEmitter`s this behaves exactly the same as calling `.listeners` on
|
313
|
-
* the emitter.
|
314
|
-
*
|
315
|
-
* For `EventTarget`s this is the only way to get the event listeners for the
|
316
|
-
* event target. This is useful for debugging and diagnostic purposes.
|
317
|
-
*
|
318
|
-
* ```js
|
319
|
-
* import { getEventListeners, EventEmitter } from 'node:events';
|
320
|
-
*
|
321
|
-
* {
|
322
|
-
* const ee = new EventEmitter();
|
323
|
-
* const listener = () => console.log('Events are fun');
|
324
|
-
* ee.on('foo', listener);
|
325
|
-
* console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]
|
326
|
-
* }
|
327
|
-
* {
|
328
|
-
* const et = new EventTarget();
|
329
|
-
* const listener = () => console.log('Events are fun');
|
330
|
-
* et.addEventListener('foo', listener);
|
331
|
-
* console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]
|
332
|
-
* }
|
333
|
-
* ```
|
334
|
-
* @since v15.2.0, v14.17.0
|
335
|
-
*/
|
336
|
-
static getEventListeners(emitter: EventTarget | NodeJS.EventEmitter, name: string | symbol): Function[];
|
337
|
-
/**
|
338
|
-
* Returns the currently set max amount of listeners.
|
339
|
-
*
|
340
|
-
* For `EventEmitter`s this behaves exactly the same as calling `.getMaxListeners` on
|
341
|
-
* the emitter.
|
342
|
-
*
|
343
|
-
* For `EventTarget`s this is the only way to get the max event listeners for the
|
344
|
-
* event target. If the number of event handlers on a single EventTarget exceeds
|
345
|
-
* the max set, the EventTarget will print a warning.
|
346
|
-
*
|
347
|
-
* ```js
|
348
|
-
* import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events';
|
349
|
-
*
|
350
|
-
* {
|
351
|
-
* const ee = new EventEmitter();
|
352
|
-
* console.log(getMaxListeners(ee)); // 10
|
353
|
-
* setMaxListeners(11, ee);
|
354
|
-
* console.log(getMaxListeners(ee)); // 11
|
355
|
-
* }
|
356
|
-
* {
|
357
|
-
* const et = new EventTarget();
|
358
|
-
* console.log(getMaxListeners(et)); // 10
|
359
|
-
* setMaxListeners(11, et);
|
360
|
-
* console.log(getMaxListeners(et)); // 11
|
361
|
-
* }
|
362
|
-
* ```
|
363
|
-
* @since v19.9.0
|
364
|
-
*/
|
365
|
-
static getMaxListeners(emitter: EventTarget | NodeJS.EventEmitter): number;
|
366
|
-
/**
|
367
|
-
* ```js
|
368
|
-
* import { setMaxListeners, EventEmitter } from 'node:events';
|
369
|
-
*
|
370
|
-
* const target = new EventTarget();
|
371
|
-
* const emitter = new EventEmitter();
|
372
|
-
*
|
373
|
-
* setMaxListeners(5, target, emitter);
|
374
|
-
* ```
|
375
|
-
* @since v15.4.0
|
376
|
-
* @param n A non-negative number. The maximum number of listeners per `EventTarget` event.
|
377
|
-
* @param eventsTargets Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, `n` is set as the default max for all newly created {EventTarget} and {EventEmitter}
|
378
|
-
* objects.
|
379
|
-
*/
|
380
|
-
static setMaxListeners(n?: number, ...eventTargets: Array<EventTarget | NodeJS.EventEmitter>): void;
|
381
|
-
/**
|
382
|
-
* Listens once to the `abort` event on the provided `signal`.
|
383
|
-
*
|
384
|
-
* Listening to the `abort` event on abort signals is unsafe and may
|
385
|
-
* lead to resource leaks since another third party with the signal can
|
386
|
-
* call `e.stopImmediatePropagation()`. Unfortunately Node.js cannot change
|
387
|
-
* this since it would violate the web standard. Additionally, the original
|
388
|
-
* API makes it easy to forget to remove listeners.
|
389
|
-
*
|
390
|
-
* This API allows safely using `AbortSignal`s in Node.js APIs by solving these
|
391
|
-
* two issues by listening to the event such that `stopImmediatePropagation` does
|
392
|
-
* not prevent the listener from running.
|
393
|
-
*
|
394
|
-
* Returns a disposable so that it may be unsubscribed from more easily.
|
395
|
-
*
|
396
|
-
* ```js
|
397
|
-
* import { addAbortListener } from 'node:events';
|
398
|
-
*
|
399
|
-
* function example(signal) {
|
400
|
-
* let disposable;
|
401
|
-
* try {
|
402
|
-
* signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
|
403
|
-
* disposable = addAbortListener(signal, (e) => {
|
404
|
-
* // Do something when signal is aborted.
|
405
|
-
* });
|
406
|
-
* } finally {
|
407
|
-
* disposable?.[Symbol.dispose]();
|
408
|
-
* }
|
409
|
-
* }
|
410
|
-
* ```
|
411
|
-
* @since v20.5.0
|
412
|
-
* @experimental
|
413
|
-
* @return Disposable that removes the `abort` listener.
|
414
|
-
*/
|
415
|
-
static addAbortListener(signal: AbortSignal, resource: (event: Event) => void): Disposable;
|
416
|
-
/**
|
417
|
-
* This symbol shall be used to install a listener for only monitoring `'error'` events. Listeners installed using this symbol are called before the regular `'error'` listeners are called.
|
418
|
-
*
|
419
|
-
* Installing a listener using this symbol does not change the behavior once an `'error'` event is emitted. Therefore, the process will still crash if no
|
420
|
-
* regular `'error'` listener is installed.
|
421
|
-
* @since v13.6.0, v12.17.0
|
422
|
-
*/
|
423
|
-
static readonly errorMonitor: unique symbol;
|
424
|
-
/**
|
425
|
-
* Value: `Symbol.for('nodejs.rejection')`
|
426
|
-
*
|
427
|
-
* See how to write a custom `rejection handler`.
|
428
|
-
* @since v13.4.0, v12.16.0
|
429
|
-
*/
|
430
|
-
static readonly captureRejectionSymbol: unique symbol;
|
431
|
-
/**
|
432
|
-
* Value: [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
|
433
|
-
*
|
434
|
-
* Change the default `captureRejections` option on all new `EventEmitter` objects.
|
435
|
-
* @since v13.4.0, v12.16.0
|
436
|
-
*/
|
437
|
-
static captureRejections: boolean;
|
438
|
-
/**
|
439
|
-
* By default, a maximum of `10` listeners can be registered for any single
|
440
|
-
* event. This limit can be changed for individual `EventEmitter` instances
|
441
|
-
* using the `emitter.setMaxListeners(n)` method. To change the default
|
442
|
-
* for _all_`EventEmitter` instances, the `events.defaultMaxListeners` property
|
443
|
-
* can be used. If this value is not a positive number, a `RangeError` is thrown.
|
444
|
-
*
|
445
|
-
* Take caution when setting the `events.defaultMaxListeners` because the
|
446
|
-
* change affects _all_ `EventEmitter` instances, including those created before
|
447
|
-
* the change is made. However, calling `emitter.setMaxListeners(n)` still has
|
448
|
-
* precedence over `events.defaultMaxListeners`.
|
449
|
-
*
|
450
|
-
* This is not a hard limit. The `EventEmitter` instance will allow
|
451
|
-
* more listeners to be added but will output a trace warning to stderr indicating
|
452
|
-
* that a "possible EventEmitter memory leak" has been detected. For any single
|
453
|
-
* `EventEmitter`, the `emitter.getMaxListeners()` and `emitter.setMaxListeners()` methods can be used to
|
454
|
-
* temporarily avoid this warning:
|
455
|
-
*
|
456
|
-
* ```js
|
457
|
-
* import { EventEmitter } from 'node:events';
|
458
|
-
* const emitter = new EventEmitter();
|
459
|
-
* emitter.setMaxListeners(emitter.getMaxListeners() + 1);
|
460
|
-
* emitter.once('event', () => {
|
461
|
-
* // do stuff
|
462
|
-
* emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));
|
463
|
-
* });
|
464
|
-
* ```
|
465
|
-
*
|
466
|
-
* The `--trace-warnings` command-line flag can be used to display the
|
467
|
-
* stack trace for such warnings.
|
468
|
-
*
|
469
|
-
* The emitted warning can be inspected with `process.on('warning')` and will
|
470
|
-
* have the additional `emitter`, `type`, and `count` properties, referring to
|
471
|
-
* the event emitter instance, the event's name and the number of attached
|
472
|
-
* listeners, respectively.
|
473
|
-
* Its `name` property is set to `'MaxListenersExceededWarning'`.
|
474
|
-
* @since v0.11.2
|
475
|
-
*/
|
476
|
-
static defaultMaxListeners: number;
|
477
|
-
}
|
478
|
-
import internal = require("node:events");
|
479
|
-
namespace EventEmitter {
|
480
|
-
// Should just be `export { EventEmitter }`, but that doesn't work in TypeScript 3.4
|
481
|
-
export { internal as EventEmitter };
|
482
|
-
export interface Abortable {
|
483
|
-
/**
|
484
|
-
* When provided the corresponding `AbortController` can be used to cancel an asynchronous action.
|
485
|
-
*/
|
486
|
-
signal?: AbortSignal | undefined;
|
487
|
-
}
|
488
|
-
|
489
|
-
export interface EventEmitterReferencingAsyncResource extends AsyncResource {
|
490
|
-
readonly eventEmitter: EventEmitterAsyncResource;
|
491
|
-
}
|
492
|
-
|
493
|
-
export interface EventEmitterAsyncResourceOptions extends AsyncResourceOptions, EventEmitterOptions {
|
494
|
-
/**
|
495
|
-
* The type of async event, this is required when instantiating `EventEmitterAsyncResource`
|
496
|
-
* directly rather than as a child class.
|
497
|
-
* @default new.target.name if instantiated as a child class.
|
498
|
-
*/
|
499
|
-
name?: string;
|
500
|
-
}
|
501
|
-
|
502
|
-
/**
|
503
|
-
* Integrates `EventEmitter` with `AsyncResource` for `EventEmitter`s that
|
504
|
-
* require manual async tracking. Specifically, all events emitted by instances
|
505
|
-
* of `events.EventEmitterAsyncResource` will run within its `async context`.
|
506
|
-
*
|
507
|
-
* ```js
|
508
|
-
* import { EventEmitterAsyncResource, EventEmitter } from 'node:events';
|
509
|
-
* import { notStrictEqual, strictEqual } from 'node:assert';
|
510
|
-
* import { executionAsyncId, triggerAsyncId } from 'node:async_hooks';
|
511
|
-
*
|
512
|
-
* // Async tracking tooling will identify this as 'Q'.
|
513
|
-
* const ee1 = new EventEmitterAsyncResource({ name: 'Q' });
|
514
|
-
*
|
515
|
-
* // 'foo' listeners will run in the EventEmitters async context.
|
516
|
-
* ee1.on('foo', () => {
|
517
|
-
* strictEqual(executionAsyncId(), ee1.asyncId);
|
518
|
-
* strictEqual(triggerAsyncId(), ee1.triggerAsyncId);
|
519
|
-
* });
|
520
|
-
*
|
521
|
-
* const ee2 = new EventEmitter();
|
522
|
-
*
|
523
|
-
* // 'foo' listeners on ordinary EventEmitters that do not track async
|
524
|
-
* // context, however, run in the same async context as the emit().
|
525
|
-
* ee2.on('foo', () => {
|
526
|
-
* notStrictEqual(executionAsyncId(), ee2.asyncId);
|
527
|
-
* notStrictEqual(triggerAsyncId(), ee2.triggerAsyncId);
|
528
|
-
* });
|
529
|
-
*
|
530
|
-
* Promise.resolve().then(() => {
|
531
|
-
* ee1.emit('foo');
|
532
|
-
* ee2.emit('foo');
|
533
|
-
* });
|
534
|
-
* ```
|
535
|
-
*
|
536
|
-
* The `EventEmitterAsyncResource` class has the same methods and takes the
|
537
|
-
* same options as `EventEmitter` and `AsyncResource` themselves.
|
538
|
-
* @since v17.4.0, v16.14.0
|
539
|
-
*/
|
540
|
-
export class EventEmitterAsyncResource extends EventEmitter {
|
541
|
-
/**
|
542
|
-
* @param options Only optional in child class.
|
543
|
-
*/
|
544
|
-
constructor(options?: EventEmitterAsyncResourceOptions);
|
545
|
-
/**
|
546
|
-
* Call all `destroy` hooks. This should only ever be called once. An error will
|
547
|
-
* be thrown if it is called more than once. This **must** be manually called. If
|
548
|
-
* the resource is left to be collected by the GC then the `destroy` hooks will
|
549
|
-
* never be called.
|
550
|
-
*/
|
551
|
-
emitDestroy(): void;
|
552
|
-
/**
|
553
|
-
* The unique `asyncId` assigned to the resource.
|
554
|
-
*/
|
555
|
-
readonly asyncId: number;
|
556
|
-
/**
|
557
|
-
* The same triggerAsyncId that is passed to the AsyncResource constructor.
|
558
|
-
*/
|
559
|
-
readonly triggerAsyncId: number;
|
560
|
-
/**
|
561
|
-
* The returned `AsyncResource` object has an additional `eventEmitter` property
|
562
|
-
* that provides a reference to this `EventEmitterAsyncResource`.
|
563
|
-
*/
|
564
|
-
readonly asyncResource: EventEmitterReferencingAsyncResource;
|
565
|
-
}
|
566
|
-
}
|
567
|
-
global {
|
568
|
-
namespace NodeJS {
|
569
|
-
interface EventEmitter<T extends EventMap<T> = DefaultEventMap> {
|
570
|
-
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: Key<K, T>, ...args: Args<K, T>): void;
|
571
|
-
/**
|
572
|
-
* Alias for `emitter.on(eventName, listener)`.
|
573
|
-
* @since v0.1.26
|
574
|
-
*/
|
575
|
-
addListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
|
576
|
-
/**
|
577
|
-
* Adds the `listener` function to the end of the listeners array for the event
|
578
|
-
* named `eventName`. No checks are made to see if the `listener` has already
|
579
|
-
* been added. Multiple calls passing the same combination of `eventName` and
|
580
|
-
* `listener` will result in the `listener` being added, and called, multiple times.
|
581
|
-
*
|
582
|
-
* ```js
|
583
|
-
* server.on('connection', (stream) => {
|
584
|
-
* console.log('someone connected!');
|
585
|
-
* });
|
586
|
-
* ```
|
587
|
-
*
|
588
|
-
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
589
|
-
*
|
590
|
-
* 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
|
591
|
-
* event listener to the beginning of the listeners array.
|
592
|
-
*
|
593
|
-
* ```js
|
594
|
-
* import { EventEmitter } from 'node:events';
|
595
|
-
* const myEE = new EventEmitter();
|
596
|
-
* myEE.on('foo', () => console.log('a'));
|
597
|
-
* myEE.prependListener('foo', () => console.log('b'));
|
598
|
-
* myEE.emit('foo');
|
599
|
-
* // Prints:
|
600
|
-
* // b
|
601
|
-
* // a
|
602
|
-
* ```
|
603
|
-
* @since v0.1.101
|
604
|
-
* @param eventName The name of the event.
|
605
|
-
* @param listener The callback function
|
606
|
-
*/
|
607
|
-
on<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
|
608
|
-
/**
|
609
|
-
* Adds a **one-time** `listener` function for the event named `eventName`. The
|
610
|
-
* next time `eventName` is triggered, this listener is removed and then invoked.
|
611
|
-
*
|
612
|
-
* ```js
|
613
|
-
* server.once('connection', (stream) => {
|
614
|
-
* console.log('Ah, we have our first user!');
|
615
|
-
* });
|
616
|
-
* ```
|
617
|
-
*
|
618
|
-
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
619
|
-
*
|
620
|
-
* 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
|
621
|
-
* event listener to the beginning of the listeners array.
|
622
|
-
*
|
623
|
-
* ```js
|
624
|
-
* import { EventEmitter } from 'node:events';
|
625
|
-
* const myEE = new EventEmitter();
|
626
|
-
* myEE.once('foo', () => console.log('a'));
|
627
|
-
* myEE.prependOnceListener('foo', () => console.log('b'));
|
628
|
-
* myEE.emit('foo');
|
629
|
-
* // Prints:
|
630
|
-
* // b
|
631
|
-
* // a
|
632
|
-
* ```
|
633
|
-
* @since v0.3.0
|
634
|
-
* @param eventName The name of the event.
|
635
|
-
* @param listener The callback function
|
636
|
-
*/
|
637
|
-
once<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
|
638
|
-
/**
|
639
|
-
* Removes the specified `listener` from the listener array for the event named `eventName`.
|
640
|
-
*
|
641
|
-
* ```js
|
642
|
-
* const callback = (stream) => {
|
643
|
-
* console.log('someone connected!');
|
644
|
-
* };
|
645
|
-
* server.on('connection', callback);
|
646
|
-
* // ...
|
647
|
-
* server.removeListener('connection', callback);
|
648
|
-
* ```
|
649
|
-
*
|
650
|
-
* `removeListener()` will remove, at most, one instance of a listener from the
|
651
|
-
* listener array. If any single listener has been added multiple times to the
|
652
|
-
* listener array for the specified `eventName`, then `removeListener()` must be
|
653
|
-
* called multiple times to remove each instance.
|
654
|
-
*
|
655
|
-
* Once an event is emitted, all listeners attached to it at the
|
656
|
-
* time of emitting are called in order. This implies that any `removeListener()` or `removeAllListeners()` calls _after_ emitting and _before_ the last listener finishes execution
|
657
|
-
* will not remove them from`emit()` in progress. Subsequent events behave as expected.
|
658
|
-
*
|
659
|
-
* ```js
|
660
|
-
* import { EventEmitter } from 'node:events';
|
661
|
-
* class MyEmitter extends EventEmitter {}
|
662
|
-
* const myEmitter = new MyEmitter();
|
663
|
-
*
|
664
|
-
* const callbackA = () => {
|
665
|
-
* console.log('A');
|
666
|
-
* myEmitter.removeListener('event', callbackB);
|
667
|
-
* };
|
668
|
-
*
|
669
|
-
* const callbackB = () => {
|
670
|
-
* console.log('B');
|
671
|
-
* };
|
672
|
-
*
|
673
|
-
* myEmitter.on('event', callbackA);
|
674
|
-
*
|
675
|
-
* myEmitter.on('event', callbackB);
|
676
|
-
*
|
677
|
-
* // callbackA removes listener callbackB but it will still be called.
|
678
|
-
* // Internal listener array at time of emit [callbackA, callbackB]
|
679
|
-
* myEmitter.emit('event');
|
680
|
-
* // Prints:
|
681
|
-
* // A
|
682
|
-
* // B
|
683
|
-
*
|
684
|
-
* // callbackB is now removed.
|
685
|
-
* // Internal listener array [callbackA]
|
686
|
-
* myEmitter.emit('event');
|
687
|
-
* // Prints:
|
688
|
-
* // A
|
689
|
-
* ```
|
690
|
-
*
|
691
|
-
* Because listeners are managed using an internal array, calling this will
|
692
|
-
* change the position indices of any listener registered _after_ the listener
|
693
|
-
* being removed. This will not impact the order in which listeners are called,
|
694
|
-
* but it means that any copies of the listener array as returned by
|
695
|
-
* the `emitter.listeners()` method will need to be recreated.
|
696
|
-
*
|
697
|
-
* When a single function has been added as a handler multiple times for a single
|
698
|
-
* event (as in the example below), `removeListener()` will remove the most
|
699
|
-
* recently added instance. In the example the `once('ping')` listener is removed:
|
700
|
-
*
|
701
|
-
* ```js
|
702
|
-
* import { EventEmitter } from 'node:events';
|
703
|
-
* const ee = new EventEmitter();
|
704
|
-
*
|
705
|
-
* function pong() {
|
706
|
-
* console.log('pong');
|
707
|
-
* }
|
708
|
-
*
|
709
|
-
* ee.on('ping', pong);
|
710
|
-
* ee.once('ping', pong);
|
711
|
-
* ee.removeListener('ping', pong);
|
712
|
-
*
|
713
|
-
* ee.emit('ping');
|
714
|
-
* ee.emit('ping');
|
715
|
-
* ```
|
716
|
-
*
|
717
|
-
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
718
|
-
* @since v0.1.26
|
719
|
-
*/
|
720
|
-
removeListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
|
721
|
-
/**
|
722
|
-
* Alias for `emitter.removeListener()`.
|
723
|
-
* @since v10.0.0
|
724
|
-
*/
|
725
|
-
off<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
|
726
|
-
/**
|
727
|
-
* Removes all listeners, or those of the specified `eventName`.
|
728
|
-
*
|
729
|
-
* It is bad practice to remove listeners added elsewhere in the code,
|
730
|
-
* particularly when the `EventEmitter` instance was created by some other
|
731
|
-
* component or module (e.g. sockets or file streams).
|
732
|
-
*
|
733
|
-
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
734
|
-
* @since v0.1.26
|
735
|
-
*/
|
736
|
-
removeAllListeners(eventName?: Key<unknown, T>): this;
|
737
|
-
/**
|
738
|
-
* By default `EventEmitter`s will print a warning if more than `10` listeners are
|
739
|
-
* added for a particular event. This is a useful default that helps finding
|
740
|
-
* memory leaks. The `emitter.setMaxListeners()` method allows the limit to be
|
741
|
-
* modified for this specific `EventEmitter` instance. The value can be set to `Infinity` (or `0`) to indicate an unlimited number of listeners.
|
742
|
-
*
|
743
|
-
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
744
|
-
* @since v0.3.5
|
745
|
-
*/
|
746
|
-
setMaxListeners(n: number): this;
|
747
|
-
/**
|
748
|
-
* Returns the current max listener value for the `EventEmitter` which is either
|
749
|
-
* set by `emitter.setMaxListeners(n)` or defaults to {@link defaultMaxListeners}.
|
750
|
-
* @since v1.0.0
|
751
|
-
*/
|
752
|
-
getMaxListeners(): number;
|
753
|
-
/**
|
754
|
-
* Returns a copy of the array of listeners for the event named `eventName`.
|
755
|
-
*
|
756
|
-
* ```js
|
757
|
-
* server.on('connection', (stream) => {
|
758
|
-
* console.log('someone connected!');
|
759
|
-
* });
|
760
|
-
* console.log(util.inspect(server.listeners('connection')));
|
761
|
-
* // Prints: [ [Function] ]
|
762
|
-
* ```
|
763
|
-
* @since v0.1.26
|
764
|
-
*/
|
765
|
-
listeners<K>(eventName: Key<K, T>): Array<Listener2<K, T>>;
|
766
|
-
/**
|
767
|
-
* Returns a copy of the array of listeners for the event named `eventName`,
|
768
|
-
* including any wrappers (such as those created by `.once()`).
|
769
|
-
*
|
770
|
-
* ```js
|
771
|
-
* import { EventEmitter } from 'node:events';
|
772
|
-
* const emitter = new EventEmitter();
|
773
|
-
* emitter.once('log', () => console.log('log once'));
|
774
|
-
*
|
775
|
-
* // Returns a new Array with a function `onceWrapper` which has a property
|
776
|
-
* // `listener` which contains the original listener bound above
|
777
|
-
* const listeners = emitter.rawListeners('log');
|
778
|
-
* const logFnWrapper = listeners[0];
|
779
|
-
*
|
780
|
-
* // Logs "log once" to the console and does not unbind the `once` event
|
781
|
-
* logFnWrapper.listener();
|
782
|
-
*
|
783
|
-
* // Logs "log once" to the console and removes the listener
|
784
|
-
* logFnWrapper();
|
785
|
-
*
|
786
|
-
* emitter.on('log', () => console.log('log persistently'));
|
787
|
-
* // Will return a new Array with a single function bound by `.on()` above
|
788
|
-
* const newListeners = emitter.rawListeners('log');
|
789
|
-
*
|
790
|
-
* // Logs "log persistently" twice
|
791
|
-
* newListeners[0]();
|
792
|
-
* emitter.emit('log');
|
793
|
-
* ```
|
794
|
-
* @since v9.4.0
|
795
|
-
*/
|
796
|
-
rawListeners<K>(eventName: Key<K, T>): Array<Listener2<K, T>>;
|
797
|
-
/**
|
798
|
-
* Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments
|
799
|
-
* to each.
|
800
|
-
*
|
801
|
-
* Returns `true` if the event had listeners, `false` otherwise.
|
802
|
-
*
|
803
|
-
* ```js
|
804
|
-
* import { EventEmitter } from 'node:events';
|
805
|
-
* const myEmitter = new EventEmitter();
|
806
|
-
*
|
807
|
-
* // First listener
|
808
|
-
* myEmitter.on('event', function firstListener() {
|
809
|
-
* console.log('Helloooo! first listener');
|
810
|
-
* });
|
811
|
-
* // Second listener
|
812
|
-
* myEmitter.on('event', function secondListener(arg1, arg2) {
|
813
|
-
* console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
|
814
|
-
* });
|
815
|
-
* // Third listener
|
816
|
-
* myEmitter.on('event', function thirdListener(...args) {
|
817
|
-
* const parameters = args.join(', ');
|
818
|
-
* console.log(`event with parameters ${parameters} in third listener`);
|
819
|
-
* });
|
820
|
-
*
|
821
|
-
* console.log(myEmitter.listeners('event'));
|
822
|
-
*
|
823
|
-
* myEmitter.emit('event', 1, 2, 3, 4, 5);
|
824
|
-
*
|
825
|
-
* // Prints:
|
826
|
-
* // [
|
827
|
-
* // [Function: firstListener],
|
828
|
-
* // [Function: secondListener],
|
829
|
-
* // [Function: thirdListener]
|
830
|
-
* // ]
|
831
|
-
* // Helloooo! first listener
|
832
|
-
* // event with parameters 1, 2 in second listener
|
833
|
-
* // event with parameters 1, 2, 3, 4, 5 in third listener
|
834
|
-
* ```
|
835
|
-
* @since v0.1.26
|
836
|
-
*/
|
837
|
-
emit<K>(eventName: Key<K, T>, ...args: Args<K, T>): boolean;
|
838
|
-
/**
|
839
|
-
* Returns the number of listeners listening for the event named `eventName`.
|
840
|
-
* If `listener` is provided, it will return how many times the listener is found
|
841
|
-
* in the list of the listeners of the event.
|
842
|
-
* @since v3.2.0
|
843
|
-
* @param eventName The name of the event being listened for
|
844
|
-
* @param listener The event handler function
|
845
|
-
*/
|
846
|
-
listenerCount<K>(eventName: Key<K, T>, listener?: Listener2<K, T>): number;
|
847
|
-
/**
|
848
|
-
* Adds the `listener` function to the _beginning_ of the listeners array for the
|
849
|
-
* event named `eventName`. No checks are made to see if the `listener` has
|
850
|
-
* already been added. Multiple calls passing the same combination of `eventName`
|
851
|
-
* and `listener` will result in the `listener` being added, and called, multiple times.
|
852
|
-
*
|
853
|
-
* ```js
|
854
|
-
* server.prependListener('connection', (stream) => {
|
855
|
-
* console.log('someone connected!');
|
856
|
-
* });
|
857
|
-
* ```
|
858
|
-
*
|
859
|
-
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
860
|
-
* @since v6.0.0
|
861
|
-
* @param eventName The name of the event.
|
862
|
-
* @param listener The callback function
|
863
|
-
*/
|
864
|
-
prependListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
|
865
|
-
/**
|
866
|
-
* 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
|
867
|
-
* listener is removed, and then invoked.
|
868
|
-
*
|
869
|
-
* ```js
|
870
|
-
* server.prependOnceListener('connection', (stream) => {
|
871
|
-
* console.log('Ah, we have our first user!');
|
872
|
-
* });
|
873
|
-
* ```
|
874
|
-
*
|
875
|
-
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
876
|
-
* @since v6.0.0
|
877
|
-
* @param eventName The name of the event.
|
878
|
-
* @param listener The callback function
|
879
|
-
*/
|
880
|
-
prependOnceListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
|
881
|
-
/**
|
882
|
-
* Returns an array listing the events for which the emitter has registered
|
883
|
-
* listeners. The values in the array are strings or `Symbol`s.
|
884
|
-
*
|
885
|
-
* ```js
|
886
|
-
* import { EventEmitter } from 'node:events';
|
887
|
-
*
|
888
|
-
* const myEE = new EventEmitter();
|
889
|
-
* myEE.on('foo', () => {});
|
890
|
-
* myEE.on('bar', () => {});
|
891
|
-
*
|
892
|
-
* const sym = Symbol('symbol');
|
893
|
-
* myEE.on(sym, () => {});
|
894
|
-
*
|
895
|
-
* console.log(myEE.eventNames());
|
896
|
-
* // Prints: [ 'foo', 'bar', Symbol(symbol) ]
|
897
|
-
* ```
|
898
|
-
* @since v6.0.0
|
899
|
-
*/
|
900
|
-
eventNames(): Array<(string | symbol) & Key2<unknown, T>>;
|
901
|
-
}
|
902
|
-
}
|
903
|
-
}
|
904
|
-
export = EventEmitter;
|
905
|
-
}
|
906
|
-
declare module "node:events" {
|
907
|
-
import events = require("events");
|
908
|
-
export = events;
|
909
|
-
}
|