UNPKG

@salesforce/apex-node

Version:

Salesforce JS library for Apex

72 lines (71 loc) 2.24 kB
export declare class NullHeapMonitor implements Disposable { checkHeapSize(): void; startMonitoring(): void; stopMonitoring(): void; [Symbol.dispose](): void; } /** * Class responsible for monitoring heap memory usage. */ export declare class HeapMonitor implements Disposable { private static instance; private logger; private intervalId?; private isMonitoring; private interval; /** * Private constructor to enforce singleton pattern. */ private constructor(); /** * Returns the singleton instance of HeapMonitor. * @returns The singleton instance. */ static getInstance(): HeapMonitor | NullHeapMonitor; /** * Checks the current heap size and logs the details. * @param [applicationArea] - Optional application area to be included in the log. */ checkHeapSize(applicationArea?: string): void; /** * Starts monitoring the heap memory usage at regular intervals. * WARNING: Monitoring is done on a schedule interval, which must stopped/cleared * or the monitor will continue to run. The symptom of this will be a node process * that seems to be hanging. * * One must call stopMonitoring or capture the instance in a scope with the * Typescript "using" * @example * ```typescript * async function main() { * await using(HeapMonitor.getInstance(), async (heapMonitor) => { * heapMonitor.startMonitoring(); * * // Simulate some work * await new Promise(resolve => setTimeout(resolve, 2000)); * * // No need to explicitly call dispose, it will be called automatically * }); * } * * main().catch(console.error); * ``` **/ startMonitoring(): void; /** * Stops monitoring the heap memory usage. * * WARNING: It is imperative that a heap monitor be stopped * before the node process exits. * * See @{link startMonitoring} */ stopMonitoring(): void; /** * dispose method that will be called when instance of HeapMonitor * is captured by Typescript "using" keyword. * * See {@link startMonitoring} */ [Symbol.dispose](): void; }