@@ -23,6 +23,10 @@ export class MonitorManager extends CoreClientAware {
23
23
// If either the board or port managed changes, a new service must
24
24
// be started.
25
25
private monitorServices = new Map < MonitorID , MonitorService > ( ) ;
26
+ private reconnectServiceCallbacks = new Map <
27
+ MonitorID ,
28
+ ( status : Status ) => void
29
+ > ( ) ;
26
30
private isUploadInProgress : boolean ;
27
31
28
32
private startMonitorPendingRequests : [
@@ -84,6 +88,7 @@ export class MonitorManager extends CoreClientAware {
84
88
85
89
const result = await monitor . start ( ) ;
86
90
postStartCallback ( result ) ;
91
+ this . reconnectServiceCallbacks . set ( monitorID , postStartCallback ) ;
87
92
}
88
93
89
94
/**
@@ -126,21 +131,29 @@ export class MonitorManager extends CoreClientAware {
126
131
* @param board board connected to port
127
132
* @param port port to monitor
128
133
*/
129
- async notifyUploadStarted ( board ?: Board , port ?: Port ) : Promise < void > {
134
+ async notifyUploadStarted (
135
+ board ?: Board ,
136
+ port ?: Port
137
+ ) : Promise < ( ( status : Status ) => void ) | undefined > {
130
138
this . isUploadInProgress = true ;
131
139
132
140
if ( ! board || ! port ) {
133
141
// We have no way of knowing which monitor
134
142
// to retrieve if we don't have this information.
135
- return ;
143
+ return undefined ;
136
144
}
137
145
const monitorID = this . monitorID ( board , port ) ;
138
146
const monitor = this . monitorServices . get ( monitorID ) ;
139
147
if ( ! monitor ) {
140
148
// There's no monitor running there, bail
141
- return ;
149
+ return undefined ;
150
+ }
151
+
152
+ const reconnectCallback = this . reconnectServiceCallbacks . get ( monitorID ) ;
153
+ await monitor . dispose ( ) ;
154
+ if ( reconnectCallback ) {
155
+ return reconnectCallback ;
142
156
}
143
- return monitor . pause ( ) ;
144
157
}
145
158
146
159
/**
@@ -151,22 +164,27 @@ export class MonitorManager extends CoreClientAware {
151
164
* @returns a Status object to know if the process has been
152
165
* started or if there have been errors.
153
166
*/
154
- async notifyUploadFinished ( board ?: Board , port ?: Port ) : Promise < Status > {
167
+ async notifyUploadFinished (
168
+ board ?: Board ,
169
+ port ?: Port ,
170
+ postStartCallback ?: ( status : Status ) => void
171
+ ) : Promise < void > {
155
172
this . isUploadInProgress = false ;
156
173
157
174
if ( ! board || ! port ) {
158
175
// We have no way of knowing which monitor
159
176
// to retrieve if we don't have this information.
160
- return Status . NOT_CONNECTED ;
161
- }
162
- const monitorID = this . monitorID ( board , port ) ;
163
- const monitor = this . monitorServices . get ( monitorID ) ;
164
- if ( ! monitor ) {
165
- // There's no monitor running there, bail
166
- return Status . NOT_CONNECTED ;
177
+ return ;
167
178
}
168
179
169
- return monitor . start ( ) ;
180
+ const monitor = this . createMonitor ( board , port ) ;
181
+ const restartServiceResult = await monitor . start ( ) ;
182
+ if ( postStartCallback ) {
183
+ postStartCallback ( restartServiceResult ) ;
184
+
185
+ const monitorID = this . monitorID ( board , port ) ;
186
+ this . reconnectServiceCallbacks . set ( monitorID , postStartCallback ) ;
187
+ }
170
188
}
171
189
172
190
async startQueuedServices ( ) : Promise < void > {
@@ -252,6 +270,7 @@ export class MonitorManager extends CoreClientAware {
252
270
monitor . onDispose (
253
271
( ( ) => {
254
272
this . monitorServices . delete ( monitorID ) ;
273
+ this . reconnectServiceCallbacks . delete ( monitorID ) ;
255
274
} ) . bind ( this )
256
275
) ;
257
276
return monitor ;
0 commit comments