MCPcopy Create free account
hub / github.com/Marus/cortex-debug / waitForPortStatusEx

Method waitForPortStatusEx

src/tcpportscanner.ts:305–333  ·  view source on GitHub ↗

* This is the workhorse function for all kinds of status queries on port:localhost * * @param opts

(opts: PortStatusArgs)

Source from the content-addressed store, hash-verified

303 * @param opts
304 */
305 protected static waitForPortStatusEx(opts: PortStatusArgs): Promise<void> {
306 opts.startTimeMs = Date.now();
307 const functor = opts.checkLocalHostAliases ? TcpPortScanner.isPortInUseEx : TcpPortScanner.isPortInUse;
308 return new Promise(function tryAgain(resolve, reject) {
309 functor(opts.port, opts.host, null)
310 .then((inUse) => {
311 // ConsoleLog(`${functor.name} returned ${inUse}`)
312 if (inUse === opts.desiredStatus) { // status match
313 return resolve();
314 } else {
315 throw new Error('tryagain');
316 }
317 }).catch((e) => {
318 if (e.message !== 'tryagain') {
319 return reject(e);
320 } else {
321 const t = Date.now() - opts.startTimeMs;
322 if (t < opts.timeOutMs) {
323 // ConsoleLog(`Setting timeout for ${opts.retryTimeMs}ms, curTime = ${t}ms`);
324 setTimeout(() => {
325 tryAgain(resolve, reject);
326 }, opts.retryTimeMs);
327 } else {
328 return reject(new Error('timeout'));
329 }
330 }
331 });
332 });
333 }
334
335 /**
336 * Wait for particular port status. We always do a minium of one try regardless of timeouts, so setting a timeout

Callers 3

waitForPortStatusMethod · 0.45
waitForPortOpenMethod · 0.45
waitForPortClosedMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected