MCPcopy
hub / github.com/chenglou/pretext / getAvailablePort

Function getAvailablePort

scripts/browser-automation.ts:96–121  ·  view source on GitHub ↗
(requestedPort: number | null = null)

Source from the content-addressed store, hash-verified

94}
95
96export async function getAvailablePort(requestedPort: number | null = null): Promise<number> {
97 if (requestedPort !== null && Number.isFinite(requestedPort) && requestedPort > 0) {
98 return requestedPort
99 }
100
101 return await new Promise((resolve, reject) => {
102 const server = createNetServer()
103 server.once('error', reject)
104 server.listen(0, '127.0.0.1', () => {
105 const address = server.address()
106 if (address === null || typeof address === 'string') {
107 reject(new Error('Failed to allocate a free port'))
108 return
109 }
110
111 const { port } = address
112 server.close(error => {
113 if (error) {
114 reject(error)
115 return
116 }
117 resolve(port)
118 })
119 })
120 })
121}
122
123const LOCK_DIR = join(process.env['TMPDIR'] ?? '/tmp', 'pretext-browser-automation-locks')
124

Callers 14

symbol-check.tsFile · 0.90
corpus-sweep.tsFile · 0.90
corpus-check.tsFile · 0.90
startProxyServerFunction · 0.90
accuracy-check.tsFile · 0.90
keep-all-check.tsFile · 0.90
benchmark-check.tsFile · 0.90
pre-wrap-check.tsFile · 0.90
corpus-taxonomy.tsFile · 0.90
startPostedReportServerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…