MCPcopy Create free account
hub / github.com/MarsWang42/Awel / waitForServer

Function waitForServer

packages/cli/src/subprocess.ts:88–103  ·  view source on GitHub ↗

* Wait for the dev server to respond on its port. * Polls with 500ms intervals up to the timeout.

(port: number, timeoutMs = 30_000)

Source from the content-addressed store, hash-verified

86 * Polls with 500ms intervals up to the timeout.
87 */
88async function waitForServer(port: number, timeoutMs = 30_000): Promise<boolean> {
89 const start = Date.now();
90 while (Date.now() - start < timeoutMs) {
91 try {
92 const res = await fetch(`http://localhost:${port}`, {
93 signal: AbortSignal.timeout(2000),
94 });
95 // Any response (even 500) means the server is up
96 if (res.status) return true;
97 } catch {
98 // Not ready yet
99 }
100 await new Promise(r => setTimeout(r, 500));
101 }
102 return false;
103}
104
105/**
106 * Spawn the dev server process and pipe its output.

Callers 1

doSpawnFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected