MCPcopy Index your code
hub / github.com/philc/vimium / getAvailablePort

Function getAvailablePort

make.js:279–299  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

277}
278
279function getAvailablePort() {
280 const min = 7000;
281 const max = 65535;
282 let count = 0;
283 const getRandomInt = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
284 let port = getRandomInt(min, max);
285 while (!isPortAvailable(port) && count < max - min) {
286 port++;
287 if (port > max) {
288 port = min;
289 }
290 if (isPortAvailable(port)) {
291 return port;
292 }
293 count++;
294 if (count >= max - min) {
295 throw new Error(`No port is available in the range ${min} - ${max}`);
296 }
297 }
298 return port;
299}
300
301async function testDom() {
302 const port = getAvailablePort();

Callers 1

testDomFunction · 0.85

Calls 2

getRandomIntFunction · 0.85
isPortAvailableFunction · 0.85

Tested by

no test coverage detected