Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 9a32f90

Browse files
authored
use promise pool to handle batch (#19)
1 parent 5b5533b commit 9a32f90

File tree

4 files changed

+4208
-3495
lines changed

4 files changed

+4208
-3495
lines changed

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@canva/dependency-tree",
3-
"version": "3.1.5",
3+
"version": "3.1.6",
44
"description": "Calculates a dependency tree for set of files",
55
"main": "dist/index.js",
66
"author": "Canva Pty Ltd",
@@ -27,6 +27,7 @@
2727
"test:watch": "jest --watch --notify"
2828
},
2929
"dependencies": {
30+
"@supercharge/promise-pool": "^2.3.2",
3031
"acorn": "^8.0.4",
3132
"builtin-modules": "^3.2.0",
3233
"cucumber-messages": "3.x",

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { TypeScriptFileProcessor } from './processors/typescript';
1717
import Resolver = require('enhanced-resolve/lib/Resolver');
1818
import SyncAsyncFileSystemDecorator = require('enhanced-resolve/lib/SyncAsyncFileSystemDecorator');
1919
import { AbstractInputFileSystem } from 'enhanced-resolve/lib/common-types';
20+
import { PromisePool } from '@supercharge/promise-pool';
2021

2122
// This is a set of built-in modules, e.g. `path`, `fs`, etc.
2223
const builtinModules = new Set(bim);
@@ -308,10 +309,9 @@ async function runInBatches(
308309
tasks: (() => Promise<void>)[],
309310
batchSize: number,
310311
): Promise<void> {
311-
for (let i = 0; i < tasks.length; i += batchSize) {
312-
const batch = tasks.slice(i, i + batchSize);
313-
await Promise.all(batch.map((task) => task()));
314-
}
312+
await PromisePool.withConcurrency(batchSize)
313+
.for(tasks)
314+
.process((task) => task());
315315
}
316316

317317
/**

0 commit comments

Comments
 (0)