@@ -159,20 +159,24 @@ export default class IBMi {
159
159
160
160
let tempLibrarySet = false ;
161
161
162
- const disconnected = async ( ) => {
163
- const choice = await vscode . window . showWarningMessage ( `Connection lost` , {
164
- modal : true ,
165
- detail : `Connection to ${ this . currentConnectionName } has dropped. Would you like to reconnect?`
166
- } , `Yes` ) ;
162
+ const timeoutHandler = async ( ) => {
163
+ if ( ! cancelToken . isCancellationRequested ) {
164
+ this . disconnect ( ) ;
167
165
168
- let disconnect = true ;
169
- if ( choice === `Yes` ) {
170
- disconnect = ! ( await this . connect ( connectionObject , true ) ) . success ;
171
- }
166
+ const choice = await vscode . window . showWarningMessage ( `Connection lost` , {
167
+ modal : true ,
168
+ detail : `Connection to ${ this . currentConnectionName } has dropped. Would you like to reconnect?`
169
+ } , `Yes` ) ;
172
170
173
- if ( disconnect ) {
174
- this . end ( ) ;
175
- } ;
171
+ let disconnect = true ;
172
+ if ( choice === `Yes` ) {
173
+ disconnect = ! ( await this . connect ( connectionObject , true ) ) . success ;
174
+ }
175
+
176
+ if ( disconnect ) {
177
+ this . end ( ) ;
178
+ } ;
179
+ }
176
180
} ;
177
181
178
182
progress . report ( {
@@ -217,9 +221,9 @@ export default class IBMi {
217
221
}
218
222
219
223
// Register handlers after we might have to abort due to bad configuration.
220
- this . client . connection ! . once ( `timeout` , disconnected ) ;
221
- this . client . connection ! . once ( `end` , disconnected ) ;
222
- this . client . connection ! . once ( `error` , disconnected ) ;
224
+ this . client . connection ! . once ( `timeout` , timeoutHandler ) ;
225
+ this . client . connection ! . once ( `end` , timeoutHandler ) ;
226
+ this . client . connection ! . once ( `error` , timeoutHandler ) ;
223
227
224
228
if ( ! reconnecting ) {
225
229
instance . setConnection ( this ) ;
@@ -935,9 +939,10 @@ export default class IBMi {
935
939
for ( const operation of delayedOperations ) {
936
940
await operation ( ) ;
937
941
}
938
- instance . fire ( "connected" ) ;
939
942
}
940
943
944
+ instance . fire ( `connected` ) ;
945
+
941
946
GlobalStorage . get ( ) . setServerSettingsCache ( this . currentConnectionName , {
942
947
aspInfo : this . aspInfo ,
943
948
qccsid : this . qccsid ,
@@ -1104,9 +1109,17 @@ export default class IBMi {
1104
1109
this . commandsExecuted += 1 ;
1105
1110
}
1106
1111
1107
- async end ( ) {
1112
+ private async disconnect ( ) {
1108
1113
this . client . connection ?. removeAllListeners ( ) ;
1109
1114
this . client . dispose ( ) ;
1115
+ this . client . connection = null ;
1116
+ instance . fire ( `disconnected` ) ;
1117
+ }
1118
+
1119
+ async end ( ) {
1120
+ if ( this . client . connection ) {
1121
+ this . disconnect ( ) ;
1122
+ }
1110
1123
1111
1124
if ( this . outputChannel ) {
1112
1125
this . outputChannel . hide ( ) ;
@@ -1124,7 +1137,6 @@ export default class IBMi {
1124
1137
] ) ;
1125
1138
1126
1139
instance . setConnection ( undefined ) ;
1127
- instance . fire ( `disconnected` ) ;
1128
1140
await vscode . commands . executeCommand ( `setContext` , `code-for-ibmi:connected` , false ) ;
1129
1141
vscode . window . showInformationMessage ( `Disconnected from ${ this . currentHost } .` ) ;
1130
1142
}
0 commit comments