@xylabs/forget
Version:
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
37 lines • 1.87 kB
TypeScript
import type { Logger } from '@xylabs/logger';
import type { Promisable, PromiseEx } from '@xylabs/promise';
import { type ForgetConfig } from './ForgetConfig.ts';
/** A function that returns a promisable value. */
type PromisableFunction<T> = () => Promisable<T>;
/**
* Manages fire-and-forget promises with tracking, timeouts, and error handling.
*/
export declare class ForgetPromise {
/** Number of currently active (unresolved) forgotten promises. */
static activeForgets: number;
/** Number of forgotten promises that threw exceptions. */
static exceptedForgets: number;
/** Logger instance used for error and warning output. */
static logger: Logger;
/** Whether any forgotten promises are still active. */
static get active(): boolean;
/**
* Waits until all forgotten promises have completed.
* @param interval - Polling interval in milliseconds.
* @param timeout - Optional maximum wait time in milliseconds.
* @returns The number of remaining active forgets (0 if all completed).
*/
static awaitInactive(interval?: number, timeout?: number): Promise<number>;
/** Handles exceptions from forgotten promises by logging error details. */
static exceptionHandler(error: Error, { name }: ForgetConfig, externalStackTrace?: string): void;
/**
* Used to explicitly launch an async function (or Promise) with awaiting it
* @param promise The promise to forget
* @param config Configuration of forget settings
*/
static forget<T>(promise: Promise<T> | PromiseEx<T> | PromisableFunction<T> | T, config?: ForgetConfig<T>): void;
/** Handles timeout events for forgotten promises by logging timeout details. */
static timeoutHandler(time: number, { name }: ForgetConfig, externalStackTrace?: string): void;
}
export {};
//# sourceMappingURL=ForgetPromise.d.ts.map