/** * Options for {@link waitForCondition } */ export type WaitForConditionOptions = { waitMs?: number | undefined; intervalMs?: number | undefined; logger?: { debug: (...args: any[]) => void; } | undefined; error?: string | Error | undefined; }; /** * Options for {@link longSleep } */ export type LongSleepOptions = { thresholdMs?: number | undefined; intervalMs?: number | undefined; progressCb?: ProgressCallback | null | undefined; }; /** * Parameter provided to a {@link ProgressCallback } */ export type Progress = { elapsedMs: number; timeLeft: number; progress: number; }; /** * Progress callback for {@link longSleep } */ export type ProgressCallback = (progress: Progress) => void; /** * An async/await version of setTimeout * @param {number} ms * @returns {Promise} */ export function sleep(ms: number): Promise; /** * An async/await way of running a method until it doesn't throw an error * @template [T=any] * @param {number} times * @param {(...args: any[]) => Promise} fn * @param {...any} args * @returns {Promise} */ export function retry(times: number, fn: (...args: any[]) => Promise, ...args: any[]): Promise; /** * Export async functions (Promises) and import this with your ES5 code to use * it with Node. * @template [R=any] * @param {any} promisey * @param {(err: any, value?: R) => void} cb * @returns {Promise} */ export function nodeify(promisey: any, cb: (err: any, value?: R | undefined) => void): Promise; /** * Node-ify an entire object of `Promise`-returning functions * @param {Record any>} promiseyMap * @returns {Recordvoid>} */ export function nodeifyAll(promiseyMap: Record any>): Record void>; /** * You can also use `retryInterval` to add a sleep in between retries. This can * be useful if you want to throttle how fast we retry. * @template [T=any] * @param {number} times * @param {number} sleepMs * @param {(...args: any[]) => Promise} fn * @param {...any} args * @returns {Promise} */ export function retryInterval(times: number, sleepMs: number, fn: (...args: any[]) => Promise, ...args: any[]): Promise; /** * @param {(...args: any[]) => any|Promise} fn * @param {...any} args */ export function asyncify(fn: (...args: any[]) => any | Promise, ...args: any[]): void; export const parallel: typeof B.all; /** * Similar to `Array.prototype.map`; runs in serial * @param {any[]} coll * @param {(value: any) => any|Promise} mapper * @returns {Promise} */ export function asyncmap(coll: any[], mapper: (value: any) => any | Promise, runInParallel?: boolean): Promise; /** * Similar to `Array.prototype.filter` * @param {any[]} coll * @param {(value: any) => any|Promise} filter * @param {boolean} runInParallel * @returns {Promise} */ export function asyncfilter(coll: any[], filter: (value: any) => any | Promise, runInParallel?: boolean): Promise; /** * Takes a condition (a function returning a boolean or boolean promise), and * waits until the condition is true. * * Throws a `/Condition unmet/` error if the condition has not been satisfied * within the allocated time, unless an error is provided in the options, as the * `error` property, which is either thrown itself, or used as the message. * * The condition result is returned if it is not falsy. If the condition throws an * error then this exception will be immediately passed through. * * The default options are: `{ waitMs: 5000, intervalMs: 500 }` * @template T * @param {() => Promise|T} condFn * @param {WaitForConditionOptions} [options] * @returns {Promise} */ export function waitForCondition(condFn: () => T | Promise, options?: WaitForConditionOptions | undefined): Promise; /** * Sometimes `Promise.delay` or `setTimeout` are inaccurate for large wait * times. To safely wait for these long times (e.g. in the 5+ minute range), you * can use `longSleep`. * * sYou can also pass a `progressCb` option which is a callback function that * receives an object with the properties `elapsedMs`, `timeLeft`, and * `progress`. This will be called on every wait interval so you can do your * wait logging or whatever. * @param {number} ms * @param {LongSleepOptions} [opts] * @returns {Promise} */ export function longSleep(ms: number, { thresholdMs, intervalMs, progressCb, }?: LongSleepOptions | undefined): Promise; import B from "bluebird"; //# sourceMappingURL=asyncbox.d.ts.map