Skip to content

Commit

Permalink
debugger: reduce scope of eslint disable comment
Browse files Browse the repository at this point in the history
Current code masks setInterval and setTimeout with promisified versions.
This can be confusing to read and causes lint errors. Replace masking
with use of pSetInterval and pSetTimeout instead.

Move disabling of lint rule from entire file to the one remaining line
(after the above changes) that still needs it.

PR-URL: #38946
Backport-PR-URL: #39446
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
Trott authored and richardlau committed Jul 22, 2021
1 parent 992f5ff commit d477e80
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lib/internal/inspector/_inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
* IN THE SOFTWARE.
*/

// TODO(aduh95): remove restricted syntax errors
/* eslint-disable no-restricted-syntax */

'use strict';

const {
Expand Down Expand Up @@ -56,10 +53,10 @@ const {
AbortController,
} = require('internal/abort_controller');

const setTimeout = util.promisify(require('timers').setTimeout);
async function* setInterval(delay) {
const pSetTimeout = util.promisify(require('timers').setTimeout);
async function* pSetInterval(delay) {
while (true) {
await setTimeout(delay);
await pSetTimeout(delay);
yield;
}
}
Expand Down Expand Up @@ -89,13 +86,13 @@ async function portIsFree(host, port, timeout = 9999) {
const ac = new AbortController();
const { signal } = ac;

setTimeout(timeout).then(() => ac.abort());
pSetTimeout(timeout).then(() => ac.abort());

const asyncIterator = setInterval(retryDelay);
const asyncIterator = pSetInterval(retryDelay);
while (true) {
await asyncIterator.next();
if (signal.aborted) {
throw new StartupError(
throw new StartupError( // eslint-disable-line no-restricted-syntax
`Timeout (${timeout}) waiting for ${host}:${port} to be free`);
}
const error = await new Promise((resolve) => {
Expand Down Expand Up @@ -255,7 +252,7 @@ class NodeInspector {
return;
} catch (error) {
debuglog('connect failed', error);
await setTimeout(1000);
await pSetTimeout(1000);
}
}
this.stdout.write(' failed to connect, please retry\n');
Expand Down

0 comments on commit d477e80

Please sign in to comment.