@@ -204,6 +204,7 @@ export class MicrobitWebUSBConnection
204
204
options : {
205
205
partial : boolean ;
206
206
progress : ( percentage : number | undefined ) => void ;
207
+ miniumProgressIncrement : number ;
207
208
} ,
208
209
) : Promise < void > {
209
210
this . flashing = true ;
@@ -232,6 +233,7 @@ export class MicrobitWebUSBConnection
232
233
options : {
233
234
partial : boolean ;
234
235
progress : ( percentage : number | undefined , partial : boolean ) => void ;
236
+ miniumProgressIncrement : number ;
235
237
} ,
236
238
) : Promise < void > {
237
239
this . log ( "Stopping serial before flash" ) ;
@@ -243,7 +245,10 @@ export class MicrobitWebUSBConnection
243
245
}
244
246
245
247
const partial = options . partial ;
246
- const progress = options . progress || ( ( ) => { } ) ;
248
+ const progress = rateLimitProgress (
249
+ options . miniumProgressIncrement ?? 0.0025 ,
250
+ options . progress || ( ( ) => { } ) ,
251
+ ) ;
247
252
248
253
const boardId = this . connection . boardSerialInfo . id ;
249
254
const boardVersion = boardId . toBoardVersion ( ) ;
@@ -516,3 +521,21 @@ const enrichedError = (err: any): DeviceError => {
516
521
}
517
522
}
518
523
} ;
524
+
525
+ const rateLimitProgress = (
526
+ miniumProgressIncrement : number ,
527
+ callback : ( value : number | undefined , partial : boolean ) => void ,
528
+ ) => {
529
+ let lastCallValue = - 1 ;
530
+ return ( value : number | undefined , partial : boolean ) => {
531
+ if (
532
+ value === undefined ||
533
+ value === 0 ||
534
+ value === 1 ||
535
+ value >= lastCallValue + miniumProgressIncrement
536
+ ) {
537
+ lastCallValue = value ?? - 1 ;
538
+ callback ( value , partial ) ;
539
+ }
540
+ } ;
541
+ } ;
0 commit comments