mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-10-30 09:16:55 +00:00
Co-authored-by: heygengenesis[bot] <262951085+heygengenesis[bot]@users.noreply.github.com> Co-authored-by: miguel.sierra <229591595+miguel-heygen@users.noreply.github.com>
28 lines
775 B
TypeScript
28 lines
775 B
TypeScript
import { readFileSync } from "node:fs";
|
|
|
|
export function testProcessIsAlive(pid: number): boolean {
|
|
if (process.platform === "linux") {
|
|
try {
|
|
const stat = readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
const state = stat.slice(stat.lastIndexOf(") ") + 2)[0];
|
|
return state !== "Z" && state !== "X";
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
try {
|
|
process.kill(pid, 0);
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export async function waitForTestCondition(check: () => boolean, timeoutMs: number): Promise<void> {
|
|
const deadline = Date.now() + timeoutMs;
|
|
while (!check()) {
|
|
if (Date.now() >= deadline) throw new Error(`Condition not met within ${timeoutMs} ms`);
|
|
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
}
|
|
}
|