checkerPool

tcmts.cli.checkers.checkerPool · #cbh4hf7a · term · runs on the server

uses process

This process's checker processes, started as they're first needed (and kept, for the next batch or push): none where it isn't the CLI (nothing to start more of), or where checkerCount is one. Each check takes a slot of the machine's (withSlot) while it runs, shared with every tcm's work.

import { withSlot } from "#codebase/tcmts/cli/budget";
import { checkerCount, startCheckers, TCM_COMMAND } from "#codebase/tcmts/cli/checkers";
import type { CheckerPool } from "#codebase/tcmts/cli/checkers";

export function checkerPool(): CheckerPool | undefined {
  const g = globalThis as unknown as Record<symbol, unknown>;
  const command = g[TCM_COMMAND] as string[] | undefined;
  const size = checkerCount();
  if (!command || size < 2) return undefined;
  const key = Symbol.for("tcm.checkers");
  const what = `checks of ${process.cwd()}${process.env.TCM_BRANCH ? ` on ${process.env.TCM_BRANCH}` : ""}`;
  return ((g[key] as CheckerPool | undefined) ??= ((pool) => ({
    size: pool.size,
    check: (req) => withSlot(what, () => pool.check(req)),
  }))(startCheckers(command, size)));
}

uses

used by