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 {
123123 fn : ( message : ipc . VscodeMessage ) => message is T ,
124124 ) : Promise < T > {
125125 return new Promise ( ( resolve , _reject ) => {
126- const reject = ( error : Error ) => {
126+ const cleanup = ( ) => {
127+ proc . off ( "error" , reject )
128+ proc . off ( "exit" , onExit )
127129 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 ( )
128139 _reject ( error )
129140 }
130141
131142 const onExit = ( code : number | null ) => {
132143 reject ( new Error ( `VS Code exited unexpectedly with code ${ code } ` ) )
133144 }
134145
135- const timeout = setTimeout ( ( ) => {
136- reject ( new Error ( "timed out" ) )
137- } , this . timeoutInterval )
138-
139146 proc . on ( "message" , ( message : ipc . VscodeMessage ) => {
140147 logger . debug ( "got message from vscode" , field ( "message" , message ) )
141- proc . off ( "error" , reject )
142- proc . off ( "exit" , onExit )
143148 if ( fn ( message ) ) {
144- clearTimeout ( timeout )
149+ cleanup ( )
145150 resolve ( message )
146151 }
147152 } )
You can’t perform that action at this time.
0 commit comments