@j-o-r/asynctracker
Version:
Keep track on unresolved async methods/promises
67 lines (66 loc) • 2.44 kB
TypeScript
export default AsyncTracker;
/**
* Represents an item in the async hooks tracking.
*/
export type AsyncHookItem = {
/**
* - The unique identifier for the async operation.
*/
key: number;
/**
* - The type of the async operation, e.g., 'PROMISE'.
*/
type: string;
/**
* - The async ID of the resource that triggered this operation.
*/
triggerAsyncId: number;
/**
* - The call stack trace when the async operation was initialized.
*/
stack: string;
/**
* - The Promise object associated with this operation, including its state and async IDs.-
*/
resource: SystemTypes;
};
/**
* /**
*/
export type SystemTypes = "PROMISE" | "TIMEOUT" | "PROCESSNEXTTICK" | "TICKOBJECT" | "SCRIPT" | "QUERYWRAP" | "FILEHANDLE" | "HTTP2SESSION" | "HTTP2STREAM" | "ZLIB" | "UDPSENDWRAP" | "WRITEWRAP" | "SHUTDOWNWRAP" | "PROMISEEXECUTOR" | "TCPCONNECTWRAP" | "GETADDRINFOREQWRAP" | "GETNAMEINFOREQWRAP" | "IMMEDIATE" | "TCPWRAP" | "TCPSERVERWRAP" | "UDPWRAP" | "FSREQCALLBACK" | "HTTPPARSER" | "PIPEWRAP" | "PIPECONNECTWRAP" | "STREAMWRAP" | "TTYWRAP" | "PROCESS" | "SIGNALWRAP" | "TIMERWRAP";
declare class AsyncTracker {
/**
* Enables tracking of asynchronous methods. Optionally, only methods of a specified type can be tracked.
* @param {SystemTypes} [type] - optional only register async methods for a specific type
*/
enable(type?: SystemTypes): void;
/**
* Disables the tracking of asynchronous methods.
*/
disable(): void;
/**
* Clears all tracked asynchronous methods.
*/
reset(): void;
report(verbose?: boolean): number;
/**
* Returns an array of unresolved asynchronous methods, optionally filtered by type
* @param {SystemTypes} [type] - The type of async methods to filter by
* @returns {AsyncHookItem[]}
*/
getUnresolved(type?: SystemTypes): AsyncHookItem[];
/**
* Returns a description of the specified asynchronous method type
* @param {SystemTypes} type - The type of asynchronous method.
* @returns {string}
*/
getTypeDescription(type: SystemTypes): string;
/**
* Adds or overwrites a custom type for asynchronous methods.
* @param {string} type - The type of asynchronous method.
* @param {string} description - the description
* @returns {void}
*/
addCustomType(type: string, description: string): void;
#private;
}