AK-21/Graphite-Industrial-Intelligence
0
1/**2 * **This module is pending deprecation.** Once a replacement API has been3 * finalized, this module will be fully deprecated. Most developers should4 * **not** have cause to use this module. Users who absolutely must have5 * the functionality that domains provide may rely on it for the time being6 * but should expect to have to migrate to a different solution7 * in the future.8 *9 * Domains provide a way to handle multiple different IO operations as a10 * single group. If any of the event emitters or callbacks registered to a11 * domain emit an `'error'` event, or throw an error, then the domain object12 * will be notified, rather than losing the context of the error in the `process.on('uncaughtException')` handler, or causing the program to13 * exit immediately with an error code.14 * @deprecated Since v1.4.2 - Deprecated15 * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/domain.js)16 */17declare module "domain" {18 import EventEmitter = require("node:events");19 /**20 * The `Domain` class encapsulates the functionality of routing errors and21 * uncaught exceptions to the active `Domain` object.22 *23 * To handle the errors that it catches, listen to its `'error'` event.24 */25 class Domain extends EventEmitter {26 /**27 * An array of event emitters that have been explicitly added to the domain.28 */29 members: EventEmitter[];30 /**31 * The `enter()` method is plumbing used by the `run()`, `bind()`, and `intercept()` methods to set the active domain. It sets `domain.active` and `process.domain` to the domain, and implicitly32 * pushes the domain onto the domain33 * stack managed by the domain module (see {@link exit} for details on the34 * domain stack). The call to `enter()` delimits the beginning of a chain of35 * asynchronous calls and I/O operations bound to a domain.36 *37 * Calling `enter()` changes only the active domain, and does not alter the domain38 * itself. `enter()` and `exit()` can be called an arbitrary number of times on a39 * single domain.40 */41 enter(): void;42 /**43 * The `exit()` method exits the current domain, popping it off the domain stack.44 * Any time execution is going to switch to the context of a different chain of45 * asynchronous calls, it's important to ensure that the current domain is exited.46 * The call to `exit()` delimits either the end of or an interruption to the chain47 * of asynchronous calls and I/O operations bound to a domain.48 *49 * If there are multiple, nested domains bound to the current execution context, `exit()` will exit any domains nested within this domain.50 *51 * Calling `exit()` changes only the active domain, and does not alter the domain52 * itself. `enter()` and `exit()` can be called an arbitrary number of times on a53 * single domain.54 */55 exit(): void;56 /**57 * Run the supplied function in the context of the domain, implicitly58 * binding all event emitters, timers, and low-level requests that are59 * created in that context. Optionally, arguments can be passed to60 * the function.61 *62 * This is the most basic way to use a domain.63 *64 * ```js65 * import domain from 'node:domain';66 * import fs from 'node:fs';67 * const d = domain.create();68 * d.on('error', (er) => {69 * console.error('Caught error!', er);70 * });71 * d.run(() => {72 * process.nextTick(() => {73 * setTimeout(() => { // Simulating some various async stuff74 * fs.open('non-existent file', 'r', (er, fd) => {75 * if (er) throw er;76 * // proceed...77 * });78 * }, 100);79 * });80 * });81 * ```82 *83 * In this example, the `d.on('error')` handler will be triggered, rather84 * than crashing the program.85 */86 run<T>(fn: (...args: any[]) => T, ...args: any[]): T;87 /**88 * Explicitly adds an emitter to the domain. If any event handlers called by89 * the emitter throw an error, or if the emitter emits an `'error'` event, it90 * will be routed to the domain's `'error'` event, just like with implicit91 * binding.92 *93 * If the `EventEmitter` was already bound to a domain, it is removed from that94 * one, and bound to this one instead.95 * @param emitter emitter to be added to the domain96 */97 add(emitter: EventEmitter): void;98 /**99 * The opposite of {@link add}. Removes domain handling from the100 * specified emitter.101 * @param emitter emitter to be removed from the domain102 */103 remove(emitter: EventEmitter): void;104 /**105 * The returned function will be a wrapper around the supplied callback106 * function. When the returned function is called, any errors that are107 * thrown will be routed to the domain's `'error'` event.108 *109 * ```js110 * const d = domain.create();111 *112 * function readSomeFile(filename, cb) {113 * fs.readFile(filename, 'utf8', d.bind((er, data) => {114 * // If this throws, it will also be passed to the domain.115 * return cb(er, data ? JSON.parse(data) : null);116 * }));117 * }118 *119 * d.on('error', (er) => {120 * // An error occurred somewhere. If we throw it now, it will crash the program121 * // with the normal line number and stack message.122 * });123 * ```124 * @param callback The callback function125 * @return The bound function126 */127 bind<T extends Function>(callback: T): T;128 /**129 * This method is almost identical to {@link bind}. However, in130 * addition to catching thrown errors, it will also intercept `Error` objects sent as the first argument to the function.131 *132 * In this way, the common `if (err) return callback(err);` pattern can be replaced133 * with a single error handler in a single place.134 *135 * ```js136 * const d = domain.create();137 *138 * function readSomeFile(filename, cb) {139 * fs.readFile(filename, 'utf8', d.intercept((data) => {140 * // Note, the first argument is never passed to the141 * // callback since it is assumed to be the 'Error' argument142 * // and thus intercepted by the domain.143 *144 * // If this throws, it will also be passed to the domain145 * // so the error-handling logic can be moved to the 'error'146 * // event on the domain instead of being repeated throughout147 * // the program.148 * return cb(null, JSON.parse(data));149 * }));150 * }151 *152 * d.on('error', (er) => {153 * // An error occurred somewhere. If we throw it now, it will crash the program154 * // with the normal line number and stack message.155 * });156 * ```157 * @param callback The callback function158 * @return The intercepted function159 */160 intercept<T extends Function>(callback: T): T;161 }162 function create(): Domain;163}164declare module "node:domain" {165 export * from "domain";166}167 