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

Method waitForPortStatusEx

src/remote/src/tcpportscanner.ts:355–383  ·  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

353 * @param opts
354 */
355 protected static waitForPortStatusEx(opts: PortStatusArgs): Promise<void> {
356 opts.startTimeMs = Date.now();
357 const functor = opts.checkLocalHostAliases ? TcpPortScanner.isPortInUseEx : TcpPortScanner.isPortInUse;
358 return new Promise(function tryAgain(resolve, reject) {
359 functor(opts.port, opts.host)
360 .then((inUse) => {
361 // ConsoleLog(`${functor.name} returned ${inUse}`)
362 if (inUse === opts.desiredStatus) { // status match
363 return resolve();
364 } else {
365 throw new Error('tryagain');
366 }
367 }).catch((e) => {
368 if (e.message !== 'tryagain') {
369 return reject(e);
370 } else {
371 const t = Date.now() - opts.startTimeMs;
372 if (t < opts.timeOutMs) {
373 // ConsoleLog(`Setting timeout for ${opts.retryTimeMs}ms, curTime = ${t}ms`);
374 setTimeout(() => {
375 tryAgain(resolve, reject);
376 }, opts.retryTimeMs);
377 } else {
378 return reject(new Error('timeout'));
379 }
380 }
381 });
382 });
383 }
384
385 /**
386 * 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