poll-until-promise
Version:
Try repeatedly for a promise to be resolved
50 lines (49 loc) • 1.63 kB
TypeScript
export type IExecuteFunction = any;
export interface IWaitForOptions {
timeout?: number;
interval?: number;
message?: string;
stopOnFailure?: boolean;
backoffFactor?: number;
backoffMaxInterval?: number;
verbose?: boolean;
maxAttempts?: number;
}
export declare class PollUntil {
_interval: number;
_timeout: number;
_executedAttempts: number;
private _stopOnFailure;
private readonly _backoffFactor;
private readonly _backoffMaxInterval;
private readonly _Console;
private readonly originalStacktraceError;
private readonly _userMessage;
private readonly _verbose;
private readonly _maxAttempts;
private _isWaiting;
private _isResolved;
private _executeFn;
private start;
private promise;
private resolve;
private reject;
private _lastError;
constructor({ interval, timeout, stopOnFailure, verbose, backoffFactor, backoffMaxInterval, message, maxAttempts, }?: IWaitForOptions);
tryEvery(interval: number): PollUntil;
stopAfter(timeout: number): PollUntil;
execute(executeFn: IExecuteFunction): Promise<any>;
getPromise(): Promise<any>;
isResolved(): boolean;
isWaiting(): boolean;
stopOnFailure(stop: boolean): PollUntil;
_applyPromiseHandlers(): void;
_timeFromStart(): number;
_shouldStopTrying(): boolean;
_attemptsExhausted(): boolean;
_executeAgain(): void;
_failedToWait(): Error;
_runFunction(): void;
_log(message: Error | string): void;
}
export declare const waitFor: (waitForFunction: IExecuteFunction, options?: IWaitForOptions) => Promise<any>;