@@ -21,6 +21,7 @@ import Diff, {
2121import Scanner , { ScanResult } from '../Scanner'
2222import * as Parallel from 'async-parallel'
2323import throttle from '@jcoreio/async-throttle'
24+ import type { ThrottledFunction } from '@jcoreio/async-throttle'
2425import Mappings , { MappingSnapshot } from '../Mappings'
2526import TResource , { IHashSettings , OrderFolderResource , TLocalTree } from '../interfaces/Resource'
2627import { TAdapter } from '../interfaces/Adapter'
@@ -37,7 +38,7 @@ export default class SyncProcess {
3738 protected server : TAdapter
3839 protected cacheTreeRoot : Folder < typeof ItemLocation . LOCAL > | null
3940 protected canceled : boolean
40- protected progressCb : ( progress :number , actionsDone ?: number ) => void
41+ protected progressCb : ThrottledFunction < [ progress : number , actionsDone : number | undefined ] , void >
4142
4243 // Stage -1
4344 protected localTreeRoot : Folder < typeof ItemLocation . LOCAL > = null
@@ -88,7 +89,7 @@ export default class SyncProcess {
8889 this . localTree = localTree
8990 this . server = server
9091
91- this . progressCb = throttle ( progressCb , 1500 ) as ( progress : number , actionsDone ?: number ) => void
92+ this . progressCb = throttle ( progressCb , 1500 )
9293 this . canceled = false
9394 this . isFirefox = self . location . protocol === 'moz-extension:'
9495 }
@@ -141,6 +142,7 @@ export default class SyncProcess {
141142 this . canceled = true
142143 this . server . cancel ( )
143144 this . localTree . cancel ( )
145+ this . progressCb . cancel ( )
144146 }
145147
146148 updateProgress ( ) :void {
@@ -176,13 +178,13 @@ export default class SyncProcess {
176178
177179 async sync ( ) : Promise < void > {
178180 // onSyncStart is already executed at this point
179- this . progressCb ( 0.15 )
181+ this . progressCb ( 0.15 , 0 )
180182
181183 this . masterLocation = ItemLocation . LOCAL
182184 await this . prepareSync ( )
183185
184186 // trees are loaded at this point
185- this . progressCb ( 0.35 )
187+ this . progressCb ( 0.35 , 0 )
186188
187189 if ( this . canceled ) {
188190 throw new CancelledSyncError ( )
@@ -195,7 +197,7 @@ export default class SyncProcess {
195197 Logger . log ( { localScanResult, serverScanResult } )
196198 this . localScanResult = localScanResult
197199 this . serverScanResult = serverScanResult
198- this . progressCb ( 0.45 )
200+ this . progressCb ( 0.45 , 0 )
199201 }
200202
201203 if ( this . canceled ) {
@@ -371,6 +373,8 @@ export default class SyncProcess {
371373 this . executeReorderings ( this . localTree , this . localReorders ) ,
372374 ] )
373375 }
376+
377+ this . progressCb . cancel ( )
374378 }
375379
376380 protected async prepareSync ( ) {
0 commit comments