Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
@@ -0,0 +1,17 @@
|
||||
export async function mapWithConcurrency<T>(items: readonly T[], concurrency: number, worker: (item: T, index: number) => Promise<void>): Promise<void> {
|
||||
const limit = Math.max(1, Math.floor(concurrency));
|
||||
let nextIndex = 0;
|
||||
|
||||
const runners = Array.from({ length: Math.min(limit, items.length) }, async () => {
|
||||
while (true) {
|
||||
const index = nextIndex;
|
||||
nextIndex += 1;
|
||||
if (index >= items.length) {
|
||||
return;
|
||||
}
|
||||
await worker(items[index] as T, index);
|
||||
}
|
||||
});
|
||||
|
||||
await Promise.all(runners);
|
||||
}
|
||||
Reference in new issue
Block a user