@freeword/meta
Version:
Meta package for Freeword: exports all core types, constants, and utilities from the src/ directory.
56 lines • 3.52 kB
TypeScript
export type ObjKey = string | symbol;
export type ClxnKey = string | number | symbol;
export type KVFunc<RT, VT = any, KT = string> = (value: VT, keyOrIndex: KT, ...args: any) => RT;
export type Collection<KT extends ClxnKey = string, VT = any> = Record<KT, VT> | VT[];
export interface PromiseWalkOpts {
parallelism?: number;
}
export type OneOrMany<ET = any> = ET | readonly ET[];
/**
* Runs the given iterable, allowing no more than parallelism to be
* awaited at any time. Results will be returned in the exact order
* of the given list.
*
* Tasks will be started in order but there are no other guarantees
* about the timing or sequence of tasks.
*
* @param coll the collection to iterate over
* @param func iterator function
* @param opts
* parallelism: number of tasks to run in parallel
* @param otherArgs additional arguments to pass to the iterator function
*
* @returns an array of results from the iterator function (given an array);
* a bag mapping keys in the original to the results of the function (given a bag)
* Returned items will always be in the same order at the input collection.
*
*/
export declare function AwaitTasks<RVT = any, VT = any, KT extends number = number>(coll: readonly VT[], func: KVFunc<RVT, VT, KT>, opts?: PromiseWalkOpts, otherArgs?: any[]): Promise<Awaited<RVT>[]>;
export declare function AwaitTasks<RVT = any, VT = any, KT extends number = number>(coll: readonly VT[], func: KVFunc<Promise<RVT>, VT, KT>, opts?: PromiseWalkOpts, otherArgs?: any[]): Promise<Awaited<RVT>[]>;
export declare function AwaitTasks<RVT = any, VT = any, KT extends string = string>(coll: Record<KT, VT>, func: KVFunc<RVT, VT, KT>, opts?: PromiseWalkOpts, otherArgs?: any[]): Promise<Awaited<RVT>[]>;
/**
*
* Applies a function with given parallelism
* if given a bag, returns a bag mapping keys in the original to the results of the function
* if given an array, returns an array holding the results of the function
* Returned items will always be in the same order at the input collection.
* Tasks will be started in order but there are no other guarantees
* about the timing or sequence of tasks.
*
* @param coll the collection to iterate over
* @param func iterator function
* @param opts
* parallelism: number of tasks to run in parallel
* @param otherArgs additional arguments to pass to the iterator function
*
*/
export declare function PromiseWalk<OT extends Record<string, any>, FT extends KVFunc<any, OT[keyof OT], keyof OT>>(coll: OT, func: FT, opts?: PromiseWalkOpts, otherArgs?: any[]): Promise<{
[key in keyof OT]: Awaited<ReturnType<FT>>;
}>;
export declare function PromiseWalk<RVT = any, VT = any, KT extends ObjKey = string>(coll: Record<KT, VT>, func: KVFunc<RVT, VT, KT>, opts?: PromiseWalkOpts, otherArgs?: any[]): Promise<Record<string, Awaited<RVT>>>;
export declare function PromiseWalk<RVT = any, VT = any, KT extends number = number>(coll: VT[], func: KVFunc<RVT, VT, KT>, opts?: PromiseWalkOpts, otherArgs?: any[]): Promise<Awaited<RVT>[]>;
export declare function PromiseWalk<RVT = any, VT = any, KT extends ClxnKey = string>(coll: Collection<KT, VT>, func: KVFunc<RVT, VT, KT>, opts?: PromiseWalkOpts, otherArgs?: any[]): Promise<Awaited<RVT>[]>;
export declare function AwaitBag<OT extends object>(obj: OT, opts?: PromiseWalkOpts): Promise<{
[key in keyof OT]: Awaited<OT[key]>;
}>;
//# sourceMappingURL=PromiseUtils.d.ts.map