From c8664319edde80645bccca8f38fcc6872c9154ae Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Thu, 6 Jul 2017 18:20:01 -0700 Subject: [PATCH] Make browser._ensureChromeIsRunning idempotent The _ensureChromeIsRunning should launch chrome only once and return the same promise for all its clients. --- lib/Browser.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Browser.js b/lib/Browser.js index a24018ef..f5a1a30f 100644 --- a/lib/Browser.js +++ b/lib/Browser.js @@ -63,6 +63,7 @@ class Browser { this._chromeArguments.push(...options.args); this._terminated = false; this._chromeProcess = null; + this._launchPromise = null; } /** @@ -96,8 +97,12 @@ class Browser { } async _ensureChromeIsRunning() { - if (this._chromeProcess) - return; + if (!this._launchPromise) + this._launchPromise = this._launchChrome(); + return this._launchPromise; + } + + async _launchChrome() { this._chromeProcess = childProcess.spawn(this._chromeExecutable, this._chromeArguments, {}); let stderr = ''; this._chromeProcess.stderr.on('data', data => stderr += data.toString('utf8'));