1
0
mirror of https://git.tuxpa.in/a/code-server.git synced 2024-12-26 12:15:26 +00:00

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 = () => {
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)
})
}