import { PromiseOr, AnyFunction } from '../Types'; export declare type resolver = (value: unknown) => unknown; export declare type ErrorHandlingStrategy = 'first' | 'replace' | 'last'; export declare type AsyncFunction = () => PromiseOr; export declare type CallbackPosition = 'front' | 'back'; export type ResolverFn = (value?: unknown) => void; export type MappingKey = `${CallbackPosition}-${ErrorHandlingStrategy}`; export type ResFirst = (resolve: ResolverFn, reject: ResolverFn, result: R, error: E | null) => void; export type ResReplace = (resolve: ResolverFn, reject: ResolverFn, result: R | E) => void; export type ResLast = (resolve: ResolverFn, reject: ResolverFn, error: E | null, result: R) => void; export type MappingTable = { 'front-first': { args: (args: unknown[], callback: AnyFunction) => unknown[]; function1: ResLast; }; 'front-replace': { args: (args: unknown[], callback: AnyFunction) => unknown[]; function1: ResReplace; }; 'front-last': { args: (args: unknown[], callback: AnyFunction) => unknown[]; function1: ResFirst; }; 'back-first': { args: (args: unknown[], callback: AnyFunction) => unknown[]; function1: ResLast; }; 'back-replace': { args: (args: unknown[], callback: AnyFunction) => unknown[]; function1: ResReplace; }; 'back-last': { args: (args: unknown[], callback: AnyFunction) => unknown[]; function1: ResFirst; }; }; export interface PromisifyOptions { callBackPosition?: CallbackPosition; errorPosition?: ErrorHandlingStrategy; } declare class PromiseUtil { #private; /** * Singleton instance of the PromiseUtil class. * @private * @static */ private static readonly instance; private constructor(); /** * Execute an array of promises sequentially and collect results and errors. * * @template T - Type of the promise results. * @param {PromiseOr[]} promises - Array of promises to execute. * @returns {Promise<[Array, Error[]]>} - A promise that resolves to an array of results and errors. */ executeSequentially(promises: PromiseOr[]): Promise<[Array, Error[]]>; /** * Handle a promise, including error handling. * * @template R - Type of the promise result. * @template E - Type of the error. * @param {PromiseOr | AsyncFunction} promise - The promise to handle. * @returns {Promise<[R | null, E | null]>} - A promise that resolves to a tuple of result and error. */ handler(promise: PromiseOr | AsyncFunction): Promise<[R | null, E | null]>; /** * Retry executing a function with a specified number of retries. * * @template T - Type of the function result. * @param {() => PromiseOr} func - The function to retry. * @param {number} [maxRetries=3] - The maximum number of retries. * @returns {Promise} A promise that resolves to the result and an array of errors. */ retry(func: () => PromiseOr, maxRetries?: number): Promise<[T | null, Error[]]>; /** * Delay execution for a specified number of milliseconds. * * @param {number} milliseconds - The delay duration in milliseconds. * @returns {Promise} A promise that resolves after the delay. */ delay(milliseconds: number): Promise; /** * Filter an array of values using an asynchronous filter function. * * @template T - Type of the values. * @param {T[]} values - The array of values to filter. * @param {(value: T) => PromiseOr} asyncFilterFunc - The asynchronous filter function. * @returns {Promise} A promise that resolves to the filtered array. */ filter(values: T[], asyncFilterFunc: (value: T) => PromiseOr): Promise; /** * Timeout a promise after a specified duration. * * @template T - Type of the promise result. * @param {PromiseOr} promise - The promise to add a timeout to. * @param {number} milliseconds - The timeout duration in milliseconds. * @returns {Promise} A promise that resolves with the result or rejects with a timeout error. */ timeout(promise: PromiseOr, milliseconds: number): Promise; /** * Execute promises in batches and collect results. * * @template T - Type of input values. * @template R - Type of promise results. * @param {T[]} values - Array of input values. * @param {number} batchSize - Size of each batch. * @param {(value: T) => PromiseOr} asyncFunc - Asynchronous function to apply to each value. * @returns {Promise} - A promise that resolves to an array of results. */ batchPromises(values: T[], batchSize: number, asyncFunc: (value: T) => PromiseOr): Promise; /** * Promisify a function, allowing customization of callback and error positions. * * @template T - Type of arguments to the function. * @template R - Type of the promise result. * @param {Function} func - The function to promisify. * @param {options} [options={ callBackPosition: "back", errorPosition: "last" }] - Options for customization. * @returns {Function} A promisified function. */ promisify(func: AnyFunction, { callBackPosition, errorPosition }?: PromisifyOptions): (...args: T) => Promise; /** * Map an array of values to an array of promises and await their results. * @param values Array of values to map to promises. * @param asyncMapFunc Function to map values to promises. * @returns Array of results. */ mapPromises(values: T[], asyncMapFunc: (value: T) => PromiseOr): Promise; /** * Concurrently map an array of values to promises with a specified concurrency limit. * @param values Array of values to map to promises. * @param asyncMapFunc Function to map values to promises. * @param concurrency Maximum number of promises to run concurrently. * @returns Array of results. */ concurrentMap(values: T[], asyncMapFunc: (value: T) => PromiseOr, concurrency: number): Promise; /** * Execute an array of promises concurrently with a specified concurrency limit. * * @template T - Type of the promise results. * @param {PromiseOr[]} promises - Array of promises to execute. * @param {number} concurrency - Maximum number of promises to run concurrently. * @returns {Promise<[Array, Error[]]>} - A promise that resolves to an array of results and errors. */ executeConcurrently(promises: PromiseOr[], concurrency: number): Promise<[Array, Error[]]>; static getInstance(): PromiseUtil; } declare const _default: PromiseUtil; export default _default;