MCPcopy Create free account
hub / github.com/modem-dev/hunk / waitUntil

Function waitUntil

scripts/daemon-memory-check.ts:154–173  ·  view source on GitHub ↗
(label: string, fn: () => Promise<T | null>, timeoutMs = 5_000)

Source from the content-addressed store, hash-verified

152}
153
154async function waitUntil<T>(label: string, fn: () => Promise<T | null>, timeoutMs = 5_000) {
155 const deadline = Date.now() + timeoutMs;
156 let lastError: unknown;
157
158 while (Date.now() < deadline) {
159 try {
160 const value = await fn();
161 if (value !== null) {
162 return value;
163 }
164 } catch (error) {
165 lastError = error;
166 }
167 await Bun.sleep(25);
168 }
169
170 throw new Error(
171 `Timed out waiting for ${label}.${lastError ? ` Last error: ${String(lastError)}` : ""}`,
172 );
173}
174
175async function readHealth(port: number): Promise<HealthResponse | null> {
176 try {

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected