From b73ea2fea2bbc80f5f363d9f40d1687d2396b280 Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 12 Nov 2020 12:03:28 -0600 Subject: [PATCH] Unbind message handler itself after getting message Also switch `once` to `on` since we `off` them later anyway so no point in making Node do it twice. --- src/node/vscode.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/node/vscode.ts b/src/node/vscode.ts index 4d933e73e..9ab22ef78 100644 --- a/src/node/vscode.ts +++ b/src/node/vscode.ts @@ -126,6 +126,7 @@ export class VscodeProvider { const cleanup = () => { proc.off("error", reject) proc.off("exit", onExit) + proc.off("message", onMessage) clearTimeout(timeout) } @@ -143,16 +144,17 @@ export class VscodeProvider { reject(new Error(`VS Code exited unexpectedly with code ${code}`)) } - proc.on("message", (message: ipc.VscodeMessage) => { + const onMessage = (message: ipc.VscodeMessage) => { logger.trace("got message from vscode", field("message", message)) if (fn(message)) { cleanup() resolve(message) } - }) + } - proc.once("error", reject) - proc.once("exit", onExit) + proc.on("message", onMessage) + proc.on("error", reject) + proc.on("exit", onExit) }) }