MCPcopy Create free account
hub / github.com/TanStack/db / waitFor

Function waitFor

packages/db-collection-e2e/src/utils/helpers.ts:6–29  ·  view source on GitHub ↗
(
  condition: () => boolean | Promise<boolean>,
  options: {
    timeout?: number
    interval?: number
    message?: string
  } = {},
)

Source from the content-addressed store, hash-verified

4 * Wait for a condition to be true with timeout
5 */
6export async function waitFor(
7 condition: () => boolean | Promise<boolean>,
8 options: {
9 timeout?: number
10 interval?: number
11 message?: string
12 } = {},
13): Promise<void> {
14 const {
15 timeout = 5000,
16 interval = 50,
17 message = `Condition not met`,
18 } = options
19
20 const start = Date.now()
21 while (Date.now() - start < timeout) {
22 if (await condition()) {
23 return
24 }
25 await sleep(interval)
26 }
27
28 throw new Error(`${message} (timeout after ${timeout}ms)`)
29}
30
31/**
32 * Sleep for specified milliseconds

Callers 12

createMutationsTestSuiteFunction · 0.90
createJoinsTestSuiteFunction · 0.90
waitForReadyFunction · 0.90
waitForItemFunction · 0.90
waitForItemRemovedFunction · 0.90
waitForUsersSyncedFunction · 0.90
waitForCollectionSizeFunction · 0.70
waitForCollectionReadyFunction · 0.70
waitForQueryDataFunction · 0.70

Calls 1

sleepFunction · 0.70

Tested by

no test coverage detected