MCPcopy
hub / github.com/cloudflare/vibesdk / waitForState

Function waitForState

container/monitor-cli.test.ts:256–287  ·  view source on GitHub ↗

* Wait for ProcessMonitor to reach a specific state

(
  monitor: ProcessMonitor,
  targetState: ProcessState,
  timeout: number = TEST_TIMEOUT
)

Source from the content-addressed store, hash-verified

254 * Wait for ProcessMonitor to reach a specific state
255 */
256function waitForState(
257 monitor: ProcessMonitor,
258 targetState: ProcessState,
259 timeout: number = TEST_TIMEOUT
260): Promise<void> {
261 return new Promise((resolve, reject) => {
262 const timeoutId = setTimeout(() => {
263 reject(new Error(`Timeout waiting for state: ${targetState} (current: ${monitor.getState()})`));
264 }, timeout);
265
266 const checkState = () => {
267 if (monitor.getState() === targetState) {
268 clearTimeout(timeoutId);
269 resolve();
270 return true;
271 }
272 return false;
273 };
274
275 if (checkState()) return;
276
277 const handler = (event: MonitoringEvent) => {
278 if (event.type === 'state_changed' && event.newState === targetState) {
279 clearTimeout(timeoutId);
280 monitor.removeListener('state_changed', handler);
281 resolve();
282 }
283 };
284
285 monitor.on('state_changed', handler);
286 });
287}
288
289/**
290 * Wait for a specific event from ProcessMonitor

Callers 1

Calls 3

checkStateFunction · 0.85
getStateMethod · 0.65
onMethod · 0.45

Tested by

no test coverage detected