Fix cleanup after getting message from vscode
This commit is contained in:
parent
79478eb89f
commit
72931edcf0
@ -123,8 +123,19 @@ export class VscodeProvider {
|
|||||||
fn: (message: ipc.VscodeMessage) => message is T,
|
fn: (message: ipc.VscodeMessage) => message is T,
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
return new Promise((resolve, _reject) => {
|
return new Promise((resolve, _reject) => {
|
||||||
const reject = (error: Error) => {
|
const cleanup = () => {
|
||||||
|
proc.off("error", reject)
|
||||||
|
proc.off("exit", onExit)
|
||||||
clearTimeout(timeout)
|
clearTimeout(timeout)
|
||||||
|
}
|
||||||
|
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
cleanup()
|
||||||
|
_reject(new Error("timed out"))
|
||||||
|
}, this.timeoutInterval)
|
||||||
|
|
||||||
|
const reject = (error: Error) => {
|
||||||
|
cleanup()
|
||||||
_reject(error)
|
_reject(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,16 +143,10 @@ export class VscodeProvider {
|
|||||||
reject(new Error(`VS Code exited unexpectedly with code ${code}`))
|
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) => {
|
proc.on("message", (message: ipc.VscodeMessage) => {
|
||||||
logger.debug("got message from vscode", field("message", message))
|
logger.debug("got message from vscode", field("message", message))
|
||||||
proc.off("error", reject)
|
|
||||||
proc.off("exit", onExit)
|
|
||||||
if (fn(message)) {
|
if (fn(message)) {
|
||||||
clearTimeout(timeout)
|
cleanup()
|
||||||
resolve(message)
|
resolve(message)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user