keepWarm

tcmts.share.keepWarm · #cc2lthu5 · term · runs anywhere

Keep the served codebase's pages made ahead: when its branch's head moves (a push, a merge), #re6fv3j5 again. It looks every two seconds.

import type { Codebase } from "#codebase/tcmts/cli/codebase";
import { warmUp } from "#codebase/tcmts/share";
import type { ShareCache } from "#codebase/tcmts/share";

export function keepWarm(served: { cb: Codebase; cache: ShareCache }): void {
  let seen = "";
  const look = () => {
    let head: string;
    try {
      head = `${served.cb.store.branch().id} ${served.cb.store.head()}`;
    } catch {
      return;
    }
    if (head === seen) return;
    seen = head;
    warmUp(served).catch((e: unknown) =>
      console.error(`the web UI's warm-up failed: ${(e as Error)?.stack ?? e}`),
    );
  };
  look();
  setInterval(look, 2000).unref();
}

uses

used by