MCPcopy Create free account
hub / github.com/PalisadoesFoundation/talawa-api / waitFor

Function waitFor

test/scripts/setup/apiSetup.test.ts:34–48  ·  view source on GitHub ↗

* Helper function to wait for a condition to become true by polling * @param condition - A function that returns true when the condition is met * @param timeout - Maximum time to wait in milliseconds (default: 5000) * @param pollInterval - Interval between checks in milliseconds (default: 10) *

(
	condition: () => boolean,
	timeout = 5000,
	pollInterval = 10,
)

Source from the content-addressed store, hash-verified

32 * @throws {Error} If the timeout elapses before the condition becomes true
33 */
34async function waitFor(
35 condition: () => boolean,
36 timeout = 5000,
37 pollInterval = 10,
38): Promise<void> {
39 const startTime = Date.now();
40 while (!condition() && Date.now() - startTime < timeout) {
41 await new Promise((resolve) => setTimeout(resolve, pollInterval));
42 }
43 if (!condition()) {
44 throw new Error(
45 `waitFor: timeout waiting for condition after ${timeout}ms`,
46 );
47 }
48}
49
50describe("Setup -> apiSetup", () => {
51 const originalEnv = { ...process.env };

Callers 1

apiSetup.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected