Add separate handler for error
Feels like it parallels better with the other handlers.
This commit is contained in:
parent
b73ea2fea2
commit
6f14b8b8dd
@ -122,9 +122,9 @@ export class VscodeProvider {
|
|||||||
proc: cp.ChildProcess,
|
proc: cp.ChildProcess,
|
||||||
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 cleanup = () => {
|
const cleanup = () => {
|
||||||
proc.off("error", reject)
|
proc.off("error", onError)
|
||||||
proc.off("exit", onExit)
|
proc.off("exit", onExit)
|
||||||
proc.off("message", onMessage)
|
proc.off("message", onMessage)
|
||||||
clearTimeout(timeout)
|
clearTimeout(timeout)
|
||||||
@ -132,15 +132,16 @@ export class VscodeProvider {
|
|||||||
|
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
cleanup()
|
cleanup()
|
||||||
_reject(new Error("timed out"))
|
reject(new Error("timed out"))
|
||||||
}, this.timeoutInterval)
|
}, this.timeoutInterval)
|
||||||
|
|
||||||
const reject = (error: Error) => {
|
const onError = (error: Error) => {
|
||||||
cleanup()
|
cleanup()
|
||||||
_reject(error)
|
reject(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onExit = (code: number | null) => {
|
const onExit = (code: number | null) => {
|
||||||
|
cleanup()
|
||||||
reject(new Error(`VS Code exited unexpectedly with code ${code}`))
|
reject(new Error(`VS Code exited unexpectedly with code ${code}`))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +154,7 @@ export class VscodeProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
proc.on("message", onMessage)
|
proc.on("message", onMessage)
|
||||||
proc.on("error", reject)
|
proc.on("error", onError)
|
||||||
proc.on("exit", onExit)
|
proc.on("exit", onExit)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user