@@ -154,24 +154,38 @@ export class MonitorManager extends CoreClientAware {
154
154
async notifyUploadFinished ( board ?: Board , port ?: Port ) : Promise < Status > {
155
155
this . isUploadInProgress = false ;
156
156
let status : Status = Status . NOT_CONNECTED ;
157
+ let monitorID ;
157
158
// We have no way of knowing which monitor
158
159
// to retrieve if we don't have this information.
159
160
if ( board && port ) {
160
- const monitorID = this . monitorID ( board , port ) ;
161
+ monitorID = this . monitorID ( board , port ) ;
161
162
const monitor = this . monitorServices . get ( monitorID ) ;
162
163
// There's no monitor running there, bail
163
164
if ( monitor ) {
164
165
status = await monitor . start ( ) ;
165
166
}
166
167
}
167
- await this . startQueuedServices ( ) ;
168
+ await this . startQueuedServices ( monitorID ) ;
168
169
return status ;
169
170
}
170
171
171
- async startQueuedServices ( ) : Promise < void > {
172
- // here we remove the first item as in all likelihood it's
173
- // probably the port we used to perform an upload
174
- const queued = this . startMonitorPendingRequests . slice ( 1 ) ;
172
+ async startQueuedServices (
173
+ monitorIDRelatedToUploadBoard ?: string // when upload initially requested
174
+ ) : Promise < void > {
175
+ let portDidChangeOnUpload = false ;
176
+ if ( monitorIDRelatedToUploadBoard ) {
177
+ portDidChangeOnUpload = ! [ ...this . monitorServices . keys ( ) ] . includes (
178
+ monitorIDRelatedToUploadBoard
179
+ ) ;
180
+ }
181
+ // if we no longer have a monitor service for the "board, port"
182
+ // combination with which we called "notifyUploadStarted", we know
183
+ // the port changed during upload, hence in our "startMonitorPendingRequests"
184
+ // we'll have our "upload port', most likely at index 0.
185
+ // We remove it, as there will no longer be a board using this "upload port"
186
+ const queued = portDidChangeOnUpload
187
+ ? this . startMonitorPendingRequests . slice ( 1 )
188
+ : this . startMonitorPendingRequests ;
175
189
this . startMonitorPendingRequests = [ ] ;
176
190
177
191
for ( const [ [ board , port ] , onFinish ] of queued ) {
0 commit comments