From 03e00131120263c38786410d48ff99f9a2144133 Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 3 Nov 2020 14:54:27 -0600 Subject: [PATCH] Unbind error/exit events once handshakes resolve --- src/node/vscode.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/node/vscode.ts b/src/node/vscode.ts index c25b7e9b..5cf826a1 100644 --- a/src/node/vscode.ts +++ b/src/node/vscode.ts @@ -51,14 +51,20 @@ export class VscodeProvider { logger.debug("setting up vs code...") return 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 === "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