MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / pickPort

Function pickPort

apps/vis/scripts/dev.mjs:29–38  ·  view source on GitHub ↗
(startPort, exclude = new Set())

Source from the content-addressed store, hash-verified

27}
28
29async function pickPort(startPort, exclude = new Set()) {
30 for (let port = startPort; port < startPort + MAX_PROBE; port += 1) {
31 if (exclude.has(port)) continue;
32 // eslint-disable-next-line no-await-in-loop
33 if (await isFree(port)) return port;
34 }
35 throw new Error(
36 `no free port in [${startPort}, ${startPort + MAX_PROBE}); something is hogging the range`,
37 );
38}
39
40const requestedApi = Number(process.env.PORT) || DEFAULT_API_PORT;
41const apiPort = await pickPort(requestedApi);

Callers 1

dev.mjsFile · 0.85

Calls 2

isFreeFunction · 0.85
hasMethod · 0.65

Tested by

no test coverage detected