MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / waitFor

Function waitFor

__tests__/watcher.test.ts:45–59  ·  view source on GitHub ↗

* Helper to wait for a condition with timeout. Used for assertions that depend * on the debounce timer (real setTimeout) firing, or on the real watcher's * event delivery in the end-to-end test.

(
  condition: () => boolean,
  timeoutMs = 2000,
  intervalMs = 25
)

Source from the content-addressed store, hash-verified

43 * event delivery in the end-to-end test.
44 */
45function waitFor(
46 condition: () => boolean,
47 timeoutMs = 2000,
48 intervalMs = 25
49): Promise<void> {
50 return new Promise((resolve, reject) => {
51 const start = Date.now();
52 const check = () => {
53 if (condition()) return resolve();
54 if (Date.now() - start > timeoutMs) return reject(new Error('waitFor timed out'));
55 setTimeout(check, intervalMs);
56 };
57 check();
58 });
59}
60
61describe('FileWatcher', () => {
62 let testDir: string;

Callers 2

watcher.test.tsFile · 0.70
untilLiveFunction · 0.70

Calls 1

checkFunction · 0.70

Tested by

no test coverage detected