initial commit

This commit is contained in:
pi
2026-04-10 23:12:17 +01:00
commit d64e050fcc
34 changed files with 6954 additions and 0 deletions

34
src/monitor.ts Normal file
View File

@@ -0,0 +1,34 @@
import { existsSync } from "node:fs";
import { readFile } from "node:fs/promises";
async function sleep(ms: number) {
await new Promise((resolve) => setTimeout(resolve, ms));
}
export async function monitorRun(input: {
eventsPath: string;
resultPath: string;
onEvent?: (event: any) => void;
pollMs?: number;
}) {
const pollMs = input.pollMs ?? 50;
let offset = 0;
while (true) {
if (existsSync(input.eventsPath)) {
const text = await readFile(input.eventsPath, "utf8");
const next = text.slice(offset);
offset = text.length;
for (const line of next.split("\n").filter(Boolean)) {
input.onEvent?.(JSON.parse(line));
}
}
if (existsSync(input.resultPath)) {
return JSON.parse(await readFile(input.resultPath, "utf8"));
}
await sleep(pollMs);
}
}