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

Function waitForEvent

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

* Wait for a specific event from ProcessMonitor

(
  monitor: ProcessMonitor,
  eventType: MonitoringEvent['type'],
  timeout: number = TEST_TIMEOUT
)

Source from the content-addressed store, hash-verified

290 * Wait for a specific event from ProcessMonitor
291 */
292function waitForEvent(
293 monitor: ProcessMonitor,
294 eventType: MonitoringEvent['type'],
295 timeout: number = TEST_TIMEOUT
296): Promise<MonitoringEvent> {
297 return new Promise((resolve, reject) => {
298 const timeoutId = setTimeout(() => {
299 reject(new Error(`Timeout waiting for event: ${eventType}`));
300 }, timeout);
301
302 const handler = (event: MonitoringEvent) => {
303 if (event.type === eventType) {
304 clearTimeout(timeoutId);
305 monitor.removeListener(eventType, handler);
306 resolve(event);
307 }
308 };
309
310 monitor.on(eventType, handler);
311 });
312}
313
314/**
315 * Spawn a mock process with the given script

Callers 1

Calls 1

onMethod · 0.45

Tested by

no test coverage detected