From 249acd5e690ec2ab83784b8312ff5e0721ea1ca9 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 5 Jun 2021 18:57:30 -0700 Subject: [PATCH] debugger: reduce scope of eslint disable comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node/pull/38946 Backport-PR-URL: https://github.com/nodejs/node/pull/39446 Reviewed-By: Antoine du Hamel Reviewed-By: Michaƫl Zasso Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Luigi Pinca --- lib/internal/inspector/_inspect.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/internal/inspector/_inspect.js b/lib/internal/inspector/_inspect.js index 924b5a7f8a9bb9..65482e791d0b4c 100644 --- a/lib/internal/inspector/_inspect.js +++ b/lib/internal/inspector/_inspect.js @@ -20,9 +20,6 @@ * IN THE SOFTWARE. */ -// TODO(aduh95): remove restricted syntax errors -/* eslint-disable no-restricted-syntax */ - 'use strict'; const { @@ -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; } } @@ -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) => { @@ -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');