MCPcopy Index your code
hub / github.com/forloopcodes/contextplus / createIdleMonitor

Function createIdleMonitor

src/core/process-lifecycle.ts:79–112  ·  view source on GitHub ↗
(options: IdleMonitorOptions)

Source from the content-addressed store, hash-verified

77}
78
79export function createIdleMonitor(options: IdleMonitorOptions): IdleMonitor {
80 if (options.timeoutMs <= 0) {
81 return {
82 touch: () => { },
83 stop: () => { },
84 };
85 }
86
87 let timer: NodeJS.Timeout | null = null;
88
89 const schedule = (): void => {
90 if (timer) clearTimeout(timer);
91 timer = setTimeout(() => {
92 timer = null;
93 if (options.isTransportAlive && options.isTransportAlive()) {
94 schedule();
95 return;
96 }
97 options.onIdle();
98 }, options.timeoutMs);
99 unrefHandle(timer);
100 };
101
102 schedule();
103
104 return {
105 touch: schedule,
106 stop: () => {
107 if (!timer) return;
108 clearTimeout(timer);
109 timer = null;
110 },
111 };
112}
113
114export function startParentMonitor(options: ParentMonitorOptions): () => void {
115 if (!Number.isFinite(options.parentPid) || options.parentPid <= 1 || options.parentPid === process.pid) {

Callers 3

mainFunction · 0.85

Calls 1

scheduleFunction · 0.70

Tested by

no test coverage detected