/* eslint-disable no-use-before-define */ import type { MapLike } from './map-like.js' type MapLikeNoSync = Omit< MapLike, typeof Symbol.toStringTag | typeof Symbol.iterator > type IteratorMethod = 'entries' | 'keys' | 'values' type GetMethod = 'get' type AnyFunction = (...args: any) => any type AsyncifyIterator> = R extends IterableIterator ? AsyncIterableIterator : never /** * Asyncify Functions */ type AsyncifyIteratorFunction = (...args: Parameters) => AsyncifyIterator> type AsyncifyBooleanFunction = (...args: Parameters) => Promise type AsyncifyMapFunction = (...args: Parameters) => Promise> type AsyncifySimpleFunction = (...args: Parameters) => Promise> type Asyncify = T extends AnyFunction ? /** * Methods */ NAME extends IteratorMethod ? AsyncifyIteratorFunction : NAME extends GetMethod ? AsyncifySimpleFunction : NAME extends Symbol ? AsyncifyIteratorFunction : ReturnType extends boolean ? AsyncifyBooleanFunction : ReturnType extends Map ? AsyncifyMapFunction : AsyncifySimpleFunction /** * Properties */ : Promise type AsyncMapBase = { [N in keyof MapLikeNoSync]: Asyncify[N]> } interface AsyncMapIterator { /** * Huan(202111): we have removed the `[Symbol.iterator]`, and add the below `[Symbol.asyncIterator]` for Async */ [Symbol.asyncIterator]: () => AsyncifyIterator< ReturnType< Map[typeof Symbol.iterator] > > } type AsyncMapLike = AsyncMapBase & AsyncMapIterator export type { AsyncMapLike, }