@naturalcycles/js-lib
Version:
Standard library for universal (browser + Node.js) javascript
20 lines (19 loc) • 755 B
TypeScript
import type { NumberOfMilliseconds, PromisableFunction } from '../types.js';
import type { DeferredPromise } from './pDefer.js';
/**
* Promisified version of setTimeout.
*
* Can return a value.
* If value is instanceof Error - rejects the Promise instead of resolving.
*/
export declare function pDelay<T>(ms?: NumberOfMilliseconds, value?: T): Promise<T>;
/**
* Promisified version of setTimeout.
*
* Wraps the passed function with try/catch,
* catch will propagate to pDelayFn rejection,
* otherwise pDelayFn will resolve with returned value.
*
* On abort() - clears the Timeout and immediately resolves the Promise with void.
*/
export declare function pDelayFn<T>(ms: NumberOfMilliseconds, fn: PromisableFunction<T>): DeferredPromise<T>;