Skip to content

Commit a5ad7c3

Browse files
committed
group
1 parent 0342758 commit a5ad7c3

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

check.ts

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import AsyncLimiterClass, {
33
AsyncCurrentLimiter,
44
} from "https://cdn.skypack.dev/@masx200/[email protected]?dts";
55
import { WalkEntry } from "https://deno.land/[email protected]/fs/_util.ts";
6+
import { group } from "./deps.ts";
67
function searchFilesNames({
78
skip,
89
}: // limiter,
9-
{
10-
skip?: RegExp | RegExp[];
11-
// limiter: AsyncCurrentLimiter;
12-
}) {
10+
{
11+
skip?: RegExp | RegExp[];
12+
// limiter: AsyncCurrentLimiter;
13+
}) {
1314
console.log("type check start!");
1415

1516
const entry_iter = walk(".", {
@@ -27,35 +28,32 @@ if (import.meta.main) {
2728

2829
async function parallel_check(
2930
entry_iter: AsyncIterableIterator<WalkEntry>,
30-
limiter: AsyncCurrentLimiter
31+
limiter: AsyncCurrentLimiter,
3132
) {
32-
const stack: string[] = [];
33+
const files: string[] = [];
3334

34-
const ps: Array<Promise<void>> = [];
3535
for await (const entry of entry_iter) {
36-
if (stack.length < 15) {
37-
stack.push(entry.path);
38-
} else {
39-
ps.push(limiter.run(() => runDenoCheck([...stack, entry.path])));
40-
stack.length = 0;
41-
}
36+
files.push(entry.path);
4237
}
43-
if (stack.length) {
44-
ps.push(limiter.run(() => runDenoCheck(stack)));
45-
}
46-
await Promise.all(ps);
38+
39+
const entries = Object.values(
40+
group(files, (_s: any, i: number) => i % 50),
41+
) as string[][];
42+
43+
await Promise.all(
44+
entries.map((stack) => limiter.run(() => runDenoCheck(stack))),
45+
);
4746
}
4847

4948
async function start() {
5049
const limiter = new AsyncLimiterClass(navigator.hardwareConcurrency);
5150
const args = parse(Deno.args);
5251
console.log(args);
53-
const skip =
54-
typeof args.skip === "string"
55-
? new RegExp(String(args.skip))
56-
: Array.isArray(args.skip)
57-
? args.skip.map((s) => new RegExp(s))
58-
: undefined;
52+
const skip = typeof args.skip === "string"
53+
? new RegExp(String(args.skip))
54+
: Array.isArray(args.skip)
55+
? args.skip.map((s) => new RegExp(s))
56+
: undefined;
5957
const entry_iter = searchFilesNames({ skip });
6058
await parallel_check(entry_iter, limiter);
6159
console.log("type check Done!");

deps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ export {
2525
export { default as groupBy } from "https://cdn.skypack.dev/[email protected]/groupBy?dts";
2626
export { default as sum } from "https://cdn.skypack.dev/[email protected]/sum?dts";
2727
export { TreeNode } from "https://cdn.skypack.dev/[email protected]?dts";
28+
export { default as group } from "https://esm.sh/[email protected]";

0 commit comments

Comments
 (0)