MCPcopy
hub / github.com/coder/mux / waitFor

Function waitFor

tests/ipc/helpers.ts:414–432  ·  view source on GitHub ↗
(
  condition: () => boolean | Promise<boolean>,
  timeoutMs = 5000,
  pollIntervalMs = 50
)

Source from the content-addressed store, hash-verified

412 * More robust than fixed sleeps for async operations
413 */
414export async function waitFor(
415 condition: () => boolean | Promise<boolean>,
416 timeoutMs = 5000,
417 pollIntervalMs = 50
418): Promise<boolean> {
419 const startTime = Date.now();
420 let currentInterval = pollIntervalMs;
421
422 while (Date.now() - startTime < timeoutMs) {
423 if (await condition()) {
424 return true;
425 }
426 await new Promise((resolve) => setTimeout(resolve, currentInterval));
427 // Exponential backoff with max 500ms
428 currentInterval = Math.min(currentInterval * 1.5, 500);
429 }
430
431 return false;
432}
433
434/**
435 * Wait for a file to exist with retry logic

Calls

no outgoing calls

Tested by 15

executeBashUntilReadyFunction · 0.72
chooseSelectOptionFunction · 0.40
renderHarnessFunction · 0.40
setupFunction · 0.40
setupWithProjectContextFunction · 0.40
findRequiredElementFunction · 0.40
openAboutDialogFunction · 0.40
findMenuItemFunction · 0.40
waitForDraftCountFunction · 0.40
findQuickArchiveButtonFunction · 0.40