File tree Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -123,25 +123,30 @@ export class VscodeProvider {
123
123
fn : ( message : ipc . VscodeMessage ) => message is T ,
124
124
) : Promise < T > {
125
125
return new Promise ( ( resolve , _reject ) => {
126
- const reject = ( error : Error ) => {
126
+ const cleanup = ( ) => {
127
+ proc . off ( "error" , reject )
128
+ proc . off ( "exit" , onExit )
127
129
clearTimeout ( timeout )
130
+ }
131
+
132
+ const timeout = setTimeout ( ( ) => {
133
+ cleanup ( )
134
+ _reject ( new Error ( "timed out" ) )
135
+ } , this . timeoutInterval )
136
+
137
+ const reject = ( error : Error ) => {
138
+ cleanup ( )
128
139
_reject ( error )
129
140
}
130
141
131
142
const onExit = ( code : number | null ) => {
132
143
reject ( new Error ( `VS Code exited unexpectedly with code ${ code } ` ) )
133
144
}
134
145
135
- const timeout = setTimeout ( ( ) => {
136
- reject ( new Error ( "timed out" ) )
137
- } , this . timeoutInterval )
138
-
139
146
proc . on ( "message" , ( message : ipc . VscodeMessage ) => {
140
147
logger . debug ( "got message from vscode" , field ( "message" , message ) )
141
- proc . off ( "error" , reject )
142
- proc . off ( "exit" , onExit )
143
148
if ( fn ( message ) ) {
144
- clearTimeout ( timeout )
149
+ cleanup ( )
145
150
resolve ( message )
146
151
}
147
152
} )
You can’t perform that action at this time.
0 commit comments