import { PromiseOrNot } from '../types/util'; /** An extended promise with additional properties and methods */ export interface HandlePromise extends Promise { /** Whether the promise is resolved or rejected */ completed: boolean; /** Whether the promise is resolved */ resolved?: boolean; /** Whether the promise is rejected */ rejected?: boolean; /** Result value the promise resolved with */ result?: T; /** Error the promise rejected with */ error?: Error; /** * Resolves the promise with specified value * @param result Value to resolve the promise with */ resolve(result?: T): void; /** * Rejects the promise with specified error * @param err Error to reject the promise with */ reject(err: Error): void; /** * Adds a timeout to reject the promise with `TimeoutError` * @param milliseconds timeout in milliseconds * @param errorMessage error message * @returns self */ timeout(milliseconds: number, errorMessage: string): HandlePromise; } /** * Creates a promise that can be used as a handle. It will not raise errors when rejected until it is explicitly * awaited or catch is set * @returns modified handle promise */ export declare function createHandlePromise(): HandlePromise; /** * Wraps a promise into a handle promise * @param promise native promise * @returns handle promise */ export declare function wrapHandlePromise(promise: Promise): HandlePromise; /** * This function ensures that a promise is returned * @param call call * @returns promise */ export declare function ensurePromise(call: () => PromiseOrNot): Promise; /** Additional delay options */ export type DelayOptions = { /** Whether to delay real time, if a stubbed frozen `sinon` clock is used */ ignoreSinonClock?: boolean; }; /** * Waits specified delay * @param ms Milliseconds to wait * @param options Additional options * @return promise resolving when the delay has ended */ export declare function delay(ms: number, options?: DelayOptions): DelayPromise; /** * Delay promise */ export interface DelayPromise extends Promise { /** * Returns whether the promise is canceled * @returns whether canceled */ get canceled(): boolean; /** * Cancels waiting and resolves the promise immediately */ cancel(): void; } /** * Assembles log4js config from logging level map * @param {Object} [config] log4js config * @param {String} [config.defaultLevel = 'INFO'] Default logging level * @param {Object} [config.levels] Logging levels * @return {Object} Log4js config */ export declare function assembleLog4jsConfig(config?: any): { appenders: { console: { type: string; }; }; categories: { default: { appenders: string[]; level: any; }; }; }; /** Options for `wait*` functions */ export type WaitOptions = { /** Wait timeout in milliseconds. Defaults to `30000` */ timeoutInMs?: number; }; /** * Waits untill specified callable will pass successfully and return true. Uses log4js logger named `helpers.wait` * @param {() => boolean|Promise} callable Callable to call until it returns true * @param {Number} [intervalInMs = 25] Interval in milliseconds between the checks * @param {WaitOptions & DelayOptions} [options] Additional wait options * @return {Promise} Promise resolving with callable return value when waited * @throws {Error|TimeoutError} Error from the callable or timeout error when timed out */ export declare function wait(callable: any, intervalInMs?: number, options?: WaitOptions & DelayOptions): Promise; /** * Waits untill specified callable will pass successfully and return true. Uses log4js logger named `helpers.wait` * @param {() => boolean|Promise} callable Callable to call until it returns true * @param {Number} [intervalInMs = 25] Interval in milliseconds between the checks * @param {WaitOptions & DelayOptions} [options] Additional wait options * @return {Promise} Promise resolving with callable return value when waited * @throws {Error|TimeoutError} Error from the callable or timeout error when timed out */ export declare function waitTrue(callable: any, intervalInMs?: number, options?: WaitOptions & DelayOptions): Promise; /** * Waits untill specified callable will pass successfully. Uses log4js logger named `helpers.wait` * @param {() => boolean|Promise} callable Callable to call * @param {Number} [intervalInMs = 25] Interval in milliseconds between the checks * @param {WaitOptions & DelayOptions} [options] Additional wait options * @return {Promise} Promise resolving with callable return value when waited * @throws {Error|TimeoutError} Error from the callable or timeout error when timed out */ export declare function waitPass(callable: () => PromiseOrNot, intervalInMs?: number, options?: WaitOptions & DelayOptions): Promise; /** * Waits untill specified callable successfully returns any non-undefined value. Uses log4js logger named `helpers.wait` * @param callable Callable to call * @param intervalInMs Interval in milliseconds between the checks * @param options Additional wait options * @return Promise resolving with callable return value when waited * @throws {Error|TimeoutError} Error from the callable or timeout error when timed out */ export declare function waitAny(callable: () => PromiseOrNot, intervalInMs?: number, options?: WaitOptions): Promise; /** * Calculates exponential backoff delay. At the initial iteration, there is no delay. At the next iteration, the delay * is `startDelay`. Further, at the every next iteration the previous delay multiplies to 2 * @param iteration current iteration, where 0 is initial iteration without delaying * @param startDelay start delay * @param maxDelay maximum delay */ export declare function expBackoffDelay(iteration: number, startDelay: number, maxDelay: number): number;