MCPcopy Index your code
hub / github.com/NativeScript/SimDeck / waitForHealth

Function waitForHealth

packages/simdeck-test/src/index.ts:802–828  ·  view source on GitHub ↗
(
  endpoint: string,
  child: ChildProcess,
  output: () => string,
)

Source from the content-addressed store, hash-verified

800}
801
802async function waitForHealth(
803 endpoint: string,
804 child: ChildProcess,
805 output: () => string,
806): Promise<void> {
807 const deadline = Date.now() + 60_000;
808 let lastError: unknown;
809 while (Date.now() < deadline) {
810 if (child.exitCode !== null) {
811 throw new Error(
812 `SimDeck isolated service exited with ${child.exitCode}.\n${output()}`,
813 );
814 }
815 try {
816 await requestJson(endpoint, "GET", "/api/health");
817 return;
818 } catch (error) {
819 lastError = error;
820 await new Promise((resolve) => setTimeout(resolve, 50));
821 }
822 }
823 throw new Error(
824 `Timed out waiting for isolated SimDeck service: ${
825 lastError instanceof Error ? lastError.message : String(lastError)
826 }\n${output()}`,
827 );
828}
829
830function captureChildOutput(child: ChildProcess): () => string {
831 const chunks: string[] = [];

Callers 1

startIsolatedServiceFunction · 0.70

Calls 1

requestJsonFunction · 0.85

Tested by

no test coverage detected