/**
 * Wait a set amount of milliseconds or until the timer is aborted.
 * @param ms - Number of milliseconds to wait
 * @param abort - Abort controller
 * @returns Promise
 */
export declare function timeout(ms: number, abort?: AbortController | AbortSignal): Promise<void>;
/**
 * Time the execution of an async function.
 * @param fn - Async function
 * @param onFinish - Callback with elapsed milliseconds
 * @returns Promise
 */
export declare function time<T>(fn: () => Promise<T>, onFinish: (elapsedMs: number) => void): Promise<T>;
/**
 * Set an execution time limit for a promise.
 * @param promise - The promise being capped to `timeoutMs` max execution time
 * @param timeoutMs - Timeout limit in milliseconds
 * @param wait - If we should wait another `timeoutMs` period for `promise` to resolve
 * @param waitHandler - If `wait` is `true`, this closure will be executed before waiting another
 * `timeoutMs` cycle
 * @returns `true` if `promise` ended gracefully, `false` if timeout was reached
 */
export declare function resolveOrTimeout(promise: Promise<void>, timeoutMs: number, wait?: boolean, waitHandler?: () => void): Promise<unknown>;
export interface Stopwatch {
    /** Milliseconds since stopwatch was created. */
    getElapsed: () => number;
    /** Seconds since stopwatch was created. */
    getElapsedSeconds: () => number;
    getElapsedAndRestart: () => number;
    restart(): void;
}
/**
 * Start a `Stopwatch` that measures elapsed time based on `process.hrtime`.
 * @returns Stopwatch
 */
export declare function stopwatch(): Stopwatch;
export type Waiter<T = void, E = Error> = Promise<T> & {
    /** Alias for `resolve` */
    finish: (result: T) => void;
    resolve: (result: T) => void;
    reject: (error: E) => void;
    /** True if the promise is resolved or rejected */
    isFinished: boolean;
    /** True only if the promise is resolved */
    isResolved: boolean;
    /** True only if the promise is rejected */
    isRejected: boolean;
};
/**
 * Creates a `Waiter` promise that can be resolved or rejected at a later time.
 * @returns Waiter
 */
export declare function waiter<T = void, E = Error>(): Waiter<T, E>;
