Make browser._ensureChromeIsRunning idempotent

The _ensureChromeIsRunning should launch chrome only once
and return the same promise for all its clients.
This commit is contained in:
Andrey Lushnikov 2017-07-06 18:20:01 -07:00
parent 6c7ae41ae6
commit c8664319ed

View File

@ -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'));