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

Commit

Permalink
use promise pool to handle batch (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
fa93hws authored Aug 18, 2022
1 parent 5b5533b commit 9a32f90
Show file tree
Hide file tree
Showing 4 changed files with 4,208 additions and 3,495 deletions.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@canva/dependency-tree",
"version": "3.1.5",
"version": "3.1.6",
"description": "Calculates a dependency tree for set of files",
"main": "dist/index.js",
"author": "Canva Pty Ltd",
Expand All @@ -27,6 +27,7 @@
"test:watch": "jest --watch --notify"
},
"dependencies": {
"@supercharge/promise-pool": "^2.3.2",
"acorn": "^8.0.4",
"builtin-modules": "^3.2.0",
"cucumber-messages": "3.x",
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { TypeScriptFileProcessor } from './processors/typescript';
import Resolver = require('enhanced-resolve/lib/Resolver');
import SyncAsyncFileSystemDecorator = require('enhanced-resolve/lib/SyncAsyncFileSystemDecorator');
import { AbstractInputFileSystem } from 'enhanced-resolve/lib/common-types';
import { PromisePool } from '@supercharge/promise-pool';

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

/**
Expand Down
Loading

0 comments on commit 9a32f90

Please sign in to comment.