/** * 异步相关的工具函数 * * utils.ts 中代码太长,拆分一下 * * @filename packages/utils/src/utils/asyncUtils.ts * @author Mr Prince * @date 2023-04-20 09:37:10 */ import { PromiseExecutor } from '../types'; /** * @description 延迟一段时间(秒) */ export declare const sleep: (timeout?: number) => Promise; /** * 重入函数,不绑定 this * 和实际的重入函数可能不太一样 * 我要做的是: * 1. 多次调用函数, * 2. 后一次调用时,前一次的调用未结束 * 3. 丢弃前一次的调用结果 * * 对js来说,同步的函数是不太可能会被中断的 * 所以我做的其实只能中断异步函数 */ export declare const reentrant: (callback: (...args: any[]) => Promise) => (...args: any[]) => Promise; /** * 重试函数 */ export declare function retry(callback: Function, times?: number): Function; /** * throw Exception when timeout */ export declare const requestTimeout: (callback: () => T | Promise, timeout: number, timeoutCallback: (value: T) => void) => Promise; /** * 生成器迭代 */ export declare function cancellable(generator: Generator, T, unknown>): [() => void, Promise]; /** * 取消 promise */ export declare const cancelPromise: (func: PromiseExecutor) => (((reason?: any) => void) | Promise)[]; /** * 直接初始化一个异步的值 * 下次获取的时候能直接取到对应的值 */ export declare const eagerGet: (func: () => Promise) => () => Promise;