Chore: dispatch write to workers

This commit is contained in:
SukkaW
2026-08-02 00:09:56 +08:00
parent 6d8070d5f3
commit fa9c02d27d
9 changed files with 528 additions and 199 deletions

View File

@@ -1,7 +1,7 @@
import { isCI } from 'ci-info';
import type { Span } from '../../trace';
import { calculateContentHash } from '../content-hash';
import { compareAndWriteFile, writeFileLines } from '../create-file';
import { compareAndWriteFile, compareAndWriteFileInWorker, writeFileLines, writeFileLinesSync } from '../create-file';
/**
* The class is not about holding rule data, instead it determines how the
@@ -98,6 +98,47 @@ export abstract class BaseWriteStrategy {
);
};
/**
* Worker-thread twin of {@link output}: identical comparison, but the write is
* synchronous since blocking a dedicated worker costs nothing.
*/
public async outputInWorker(
span: Span,
title: string,
description: string[] | readonly string[],
date: Date,
filePath: string
): Promise<void> {
const result = this.result;
if (!result) {
return;
}
if (isCI && this.skipCompareOnCI) {
writeFileLinesSync(
span,
this.withPadding(title, description, date, result, null),
filePath
);
return;
}
const contentHash = calculateContentHash(title, description, result);
await compareAndWriteFileInWorker(
span,
this.withPadding(
title,
description,
date,
result,
contentHash
),
filePath,
contentHash
);
}
public get content() {
return this.result;
}