Skip to content

Commit ae07db4

Browse files
author
hirsch88
committed
improve util times
1 parent 5f58109 commit ae07db4

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/lib/seed/utils.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,5 @@ export const isPromiseLike = (o: any): boolean => !!o && (typeof o === 'object'
1111
/**
1212
* Times repeats a function n times
1313
*/
14-
export const times = async <TResult>(n: number, iteratee: (index: number) => Promise<TResult>): Promise<TResult[]> => {
15-
const rs = [] as TResult[];
16-
for (let i = 0; i < n; i++) {
17-
const r = await iteratee(i);
18-
rs.push(r);
19-
}
20-
return rs;
21-
};
14+
export const times = async <TResult>(n: number, iteratee: (index: number) => Promise<TResult>): Promise<TResult[]> =>
15+
Promise.all(new Array(n).map(async (v, i) => await iteratee(i)));

0 commit comments

Comments
 (0)