UNPKG

@push.rocks/smartpromise

Version:

A TypeScript library for managing promises and Deferred constructs, simplifying asynchronous programming.

30 lines (29 loc) 1.44 kB
export * from './smartpromise.classes.cumulativedeferred.js'; export * from './smartpromise.classes.deferred.js'; /** * Creates a new resolved promise for the provided value. */ export declare const resolvedPromise: <T>(value?: T) => Promise<T>; /** * Creates a new rejected promise for the provided reason. */ export declare const rejectedPromise: (err: any) => Promise<never>; interface IAsyncFunction<T> { (someArg: T): Promise<T>; } /** * accepts an array of inputs and a function that accepts the input. * runs all items with the function and returns the result array when all items have run * @param inputArg * @param functionArg */ export declare const map: <T>(inputArg: T[], functionArg: IAsyncFunction<T>) => Promise<any[]>; export declare const timeoutWrap: <T = any>(promiseArg: Promise<T>, timeoutInMsArg: number, rejectArg?: boolean) => Promise<T>; export declare const timeoutAndContinue: <T = any>(promiseArg: Promise<T>, timeoutInMsArg?: number) => Promise<T>; export declare const getFirstTrueOrFalse: (promisesArg: Promise<boolean>[]) => Promise<boolean>; /** * Converts a Node.js-style callback-based function into a Promise. * @param fn The function that expects a callback. * @returns A Promise that resolves with the result of the function or rejects with an error. */ export declare const fromCallback: <T>(fn: (callback: (err: NodeJS.ErrnoException | null, result?: T) => void) => void) => Promise<T>;