Fix potential 500 when loading in parallel

This commit is contained in:
Asher 2020-10-30 14:50:06 -05:00
parent 07e7c38ea2
commit 9ad7d0b7a3
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A
1 changed files with 10 additions and 7 deletions

View File

@ -50,12 +50,15 @@ export class VscodeHttpProvider extends HttpProvider {
logger.debug("setting up vs code...") logger.debug("setting up vs code...")
return new Promise<WorkbenchOptions>((resolve, reject) => { return new Promise<WorkbenchOptions>((resolve, reject) => {
vscode.once("message", (message: VscodeMessage) => { const onMessage = (message: VscodeMessage) => {
logger.debug("got message from vs code", field("message", message)) // There can be parallel initializations so wait for the right ID.
return message.type === "options" && message.id === id if (message.type === "options" && message.id === id) {
? resolve(message.options) logger.trace("got message from vs code", field("message", message))
: reject(new Error("Unexpected response during initialization")) vscode.off("message", onMessage)
}) resolve(message.options)
}
}
vscode.on("message", onMessage)
vscode.once("error", reject) vscode.once("error", reject)
vscode.once("exit", (code) => reject(new Error(`VS Code exited unexpectedly with code ${code}`))) vscode.once("exit", (code) => reject(new Error(`VS Code exited unexpectedly with code ${code}`)))
this.send({ type: "init", id, options }, vscode) this.send({ type: "init", id, options }, vscode)
@ -77,7 +80,7 @@ export class VscodeHttpProvider extends HttpProvider {
this._vscode = new Promise((resolve, reject) => { this._vscode = new Promise((resolve, reject) => {
vscode.once("message", (message: VscodeMessage) => { vscode.once("message", (message: VscodeMessage) => {
logger.debug("got message from vs code", field("message", message)) logger.trace("got message from vs code", field("message", message))
return message.type === "ready" return message.type === "ready"
? resolve(vscode) ? resolve(vscode)
: reject(new Error("Unexpected response waiting for ready response")) : reject(new Error("Unexpected response waiting for ready response"))