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.
This commit is contained in:
Asher 2020-11-12 12:03:28 -06:00
parent e1702a1d21
commit b73ea2fea2
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A

View File

@ -126,6 +126,7 @@ export class VscodeProvider {
const cleanup = () => { const cleanup = () => {
proc.off("error", reject) proc.off("error", reject)
proc.off("exit", onExit) proc.off("exit", onExit)
proc.off("message", onMessage)
clearTimeout(timeout) clearTimeout(timeout)
} }
@ -143,16 +144,17 @@ export class VscodeProvider {
reject(new Error(`VS Code exited unexpectedly with code ${code}`)) 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)) logger.trace("got message from vscode", field("message", message))
if (fn(message)) { if (fn(message)) {
cleanup() cleanup()
resolve(message) resolve(message)
} }
}) }
proc.once("error", reject) proc.on("message", onMessage)
proc.once("exit", onExit) proc.on("error", reject)
proc.on("exit", onExit)
}) })
} }