Open History to see the last commit
1import type { ServerEventLoopStall } from "@t3tools/contracts";
2
3export interface HostFreezeNotice {
4 readonly title: string;
5 readonly description: string;
6}
7
8/**
9 * Says why a host stopped answering, from the recent stall it reports on
10 * connect. Web shows it as a toast, mobile in the environment's connection row.
11 */
12export function hostFreezeNotice(
13 hostLabel: string,
14 stall: ServerEventLoopStall | undefined,
15): HostFreezeNotice | null {
16 if (stall === undefined) return null;
17 const { loadAverage, cpuCount } = stall;
18 return {
19 title: `${hostLabel} froze for ${Math.round(stall.durationMs / 1000)}s`,
20 description:
21 loadAverage !== undefined && loadAverage > cpuCount
22 ? `Its CPU is overloaded (load ${Math.round(loadAverage)} on ${cpuCount} cores).`
23 : `T3 Code on ${hostLabel} was too busy to answer.`,
24 };
25}