From 72931edcf010c2e6ce9872f7e1ab974f999e09cb Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 12 Nov 2020 11:16:21 -0600 Subject: [PATCH] Fix cleanup after getting message from vscode --- src/node/vscode.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/node/vscode.ts b/src/node/vscode.ts index 9ba7b8a9..6761a6d1 100644 --- a/src/node/vscode.ts +++ b/src/node/vscode.ts @@ -123,8 +123,19 @@ export class VscodeProvider { fn: (message: ipc.VscodeMessage) => message is T, ): Promise { return new Promise((resolve, _reject) => { - const reject = (error: Error) => { + const cleanup = () => { + proc.off("error", reject) + proc.off("exit", onExit) clearTimeout(timeout) + } + + const timeout = setTimeout(() => { + cleanup() + _reject(new Error("timed out")) + }, this.timeoutInterval) + + const reject = (error: Error) => { + cleanup() _reject(error) } @@ -132,16 +143,10 @@ export class VscodeProvider { reject(new Error(`VS Code exited unexpectedly with code ${code}`)) } - const timeout = setTimeout(() => { - reject(new Error("timed out")) - }, this.timeoutInterval) - proc.on("message", (message: ipc.VscodeMessage) => { logger.debug("got message from vscode", field("message", message)) - proc.off("error", reject) - proc.off("exit", onExit) if (fn(message)) { - clearTimeout(timeout) + cleanup() resolve(message) } })