Unbind error/exit events once handshakes resolve

This commit is contained in:
Asher 2020-11-03 14:54:27 -06:00
parent e243f6e369
commit 03e0013112
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A

View File

@ -51,14 +51,20 @@ export class VscodeProvider {
logger.debug("setting up vs code...")
return new Promise<ipc.WorkbenchOptions>((resolve, reject) => {
const onExit = (code: number | null) => reject(new Error(`VS Code exited unexpectedly with code ${code}`))
vscode.once("message", (message: ipc.VscodeMessage) => {
logger.debug("got message from vs code", field("message", message))
vscode.off("error", reject)
vscode.off("exit", onExit)
return message.type === "options" && message.id === id
? resolve(message.options)
: reject(new Error("Unexpected response during initialization"))
})
vscode.once("error", reject)
vscode.once("exit", (code) => reject(new Error(`VS Code exited unexpectedly with code ${code}`)))
vscode.once("exit", onExit)
this.send(
{
type: "init",
@ -90,14 +96,19 @@ export class VscodeProvider {
})
this._vscode = new Promise((resolve, reject) => {
const onExit = (code: number | null) => reject(new Error(`VS Code exited unexpectedly with code ${code}`))
vscode.once("message", (message: ipc.VscodeMessage) => {
logger.debug("got message from vs code", field("message", message))
vscode.off("error", reject)
vscode.off("exit", onExit)
return message.type === "ready"
? resolve(vscode)
: reject(new Error("Unexpected response waiting for ready response"))
})
vscode.once("error", reject)
vscode.once("exit", (code) => reject(new Error(`VS Code exited unexpectedly with code ${code}`)))
vscode.once("exit", onExit)
})
return this._vscode