MCPcopy Index your code
hub / github.com/coder/mux / waitForCondition

Function waitForCondition

src/node/services/agentSession.postCompactionRefresh.test.ts:16–39  ·  view source on GitHub ↗
(assertion: () => void)

Source from the content-addressed store, hash-verified

14// The actual post-compaction state computation is covered elsewhere.
15
16async function waitForCondition(assertion: () => void): Promise<void> {
17 const deadline = Date.now() + 1000;
18 let lastError: unknown;
19
20 while (Date.now() < deadline) {
21 try {
22 assertion();
23 return;
24 } catch (error) {
25 lastError = error;
26 await new Promise((resolve) => setTimeout(resolve, 10));
27 }
28 }
29
30 try {
31 assertion();
32 } catch (error) {
33 if (error instanceof Error) throw error;
34 throw new Error(String(error));
35 }
36
37 if (lastError instanceof Error) throw lastError;
38 if (lastError != null) throw new Error("condition failed with non-Error value");
39}
40
41describe("AgentSession post-compaction refresh trigger", () => {
42 let historyCleanup: (() => Promise<void>) | undefined;

Calls

no outgoing calls

Tested by

no test coverage detected