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

Function reserveLoopbackPort

scripts/daemon-memory-check.ts:141–152  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

139}
140
141async function reserveLoopbackPort() {
142 const listener = createServer(() => undefined);
143 await new Promise<void>((resolve, reject) => {
144 listener.once("error", reject);
145 listener.listen(0, "127.0.0.1", resolve);
146 });
147
148 const address = listener.address();
149 const port = typeof address === "object" && address ? address.port : 0;
150 await new Promise<void>((resolve) => listener.close(() => resolve()));
151 return port;
152}
153
154async function waitUntil<T>(label: string, fn: () => Promise<T | null>, timeoutMs = 5_000) {
155 const deadline = Date.now() + timeoutMs;

Callers 1

mainFunction · 0.70

Calls 2

addressMethod · 0.80
closeMethod · 0.65

Tested by

no test coverage detected