/// /// import { AbstractCursor } from 'mongodb'; export declare const LOG_PREFIX = "[Timeoutify]"; export declare enum TimeoutifyStatus { Aborted = 0, TimedOut = 1, Running = 2, Finished = 3 } export declare class Timeoutify { readonly startedAt: number; private readonly timeoutMS; private readonly abortController; private readonly logPrefix; private statusInternal; private readonly logger; private readonly handle; constructor({ timeoutMS, logPrefix, logger, }: { readonly timeoutMS: number; readonly logPrefix?: string; readonly logger?: Pick; }); /** * This is the time left in milliseconds before the timeout is reached. Used for handling MongoDB timeouts. */ get timeLeftMS(): number; /** * Pass this AbortSignal to your async functions to abort them when the request is aborted or times out. * */ get abortSignal(): AbortSignal; /** * This is the status of the Timeoutify instance. It's usually `Running`. If the timeout is reached, it's `Timeout`. * If the request is aborted in some other way, it's `Aborted`. If the request is marked as finished, it's `Finished`. */ get status(): TimeoutifyStatus; /** * Call this when you want to abort the request, for example when the client closes the connection. * */ abort(): this; /** * Call this when the request has finished, to prevent triggering of aborts that you don't want. * */ finished(): this; /** * This ensures the MongoDB Operation is never running for longer than the timeout. * */ runMongoOpWithTimeout(cursor: AbstractCursor): Promise; static patchMongoCursorWithTimeout(maxTimeMs: number): void; static noop(): Timeoutify; } export default Timeoutify;