UNPKG

com-tools

Version:

com-tools 提供了一些通用的工具函数;

70 lines 3.09 kB
import type { AnyFunction, ResolveData } from "type-tls"; /** * 异步串行调用函数 * @remarks * 依次调用函数 * 当发生异常时,会终止后续函数的调用,并抛出异常 * @param funs 函数数组 * @param thisValue 函数调用时的 this 值 * @param args 函数调用时的参数数组 * @returns 函数调用结果数组 */ export declare function asyncSerialCallFuns<Fun extends AnyFunction>(funs: Iterable<Fun>, thisValue?: any, args?: any[] | null): Promise<ResolveData<ReturnType<Fun>>[]>; /** * callFuns 的返回值的类型 * @param funs 函数数组 * @param thisValue 函数调用时的 this 值 * @param args 函数调用时的参数数组 * @returns 函数调用结果数组 */ export type SerialCallFunsReturn<Fun extends AnyFunction> = ResolveData<ReturnType<Fun>>[] | Promise<ResolveData<ReturnType<Fun>>[]>; /** * 串行调用函数 * @remarks * 依次调用函数 * 当函数数组中包含异步函数时,会等待所有异步函数解决后再返回结果数组。 * 当函数数组中不包含异步函数时,会同步调用所有函数并返回结果数组。 * * 当发生异常时,会终止后续函数的调用,并抛出异常 * * @param funs 函数数组 * @param thisValue 函数调用时的 this 值 * @param args 函数调用时的参数数组 * @returns 函数调用结果数组 */ export declare function serialCallFuns<Fun extends AnyFunction>(funs: Fun[], thisValue?: any, args?: any[] | null): SerialCallFunsReturn<Fun>; /** * 串行调用函数时的异常处理函数 * @param error 异常对象 * @param fun 发生异常的函数 */ export type CallFunOnError = (error: any, fun: AnyFunction) => void; /** * 异步串行调用所有函数 * @remarks * 依次调用函数 * 当发生异常时,不会终止,还会继续调用后续函数 * @param funs 函数数组 * @param thisValue 函数调用时的 this 值 * @param args 函数调用时的参数数组 * @param onError 函数调用时的异常处理函数;this 为 thisValue * @returns 函数调用结果数组 */ export declare function asyncSerialCallAllFuns<Fun extends AnyFunction>(funs: Iterable<Fun>, thisValue?: any, args?: any[] | null, onError?: CallFunOnError | null): Promise<ResolveData<ReturnType<Fun>>[]>; /** * 串行调用函数 * @remarks * 依次调用函数 * 当函数数组中包含异步函数时,会等待所有异步函数解决后再返回结果数组。 * 当函数数组中不包含异步函数时,会同步调用所有函数并返回结果数组。 * * 当发生异常时,不会终止,还会继续调用后续函数 * * @param funs 函数数组 * @param thisValue 函数调用时的 this 值 * @param args 函数调用时的参数数组 * @param onError 函数调用时的异常处理函数;this 为 thisValue * @returns 函数调用结果数组 */ export declare function serialCallAllFuns<Fun extends AnyFunction>(funs: Fun[], thisValue?: any, args?: any[] | null, onError?: CallFunOnError | null): SerialCallFunsReturn<Fun>; //# sourceMappingURL=async.d.ts.map