@@ -10,14 +10,34 @@ export interface ServerCrudLocalHistorySyncOpts {
1010 * Number of milliseconds after which remote calls are considered timed out.
1111 */
1212 remoteTimeout ?: number ;
13+
14+ /**
15+ * Minimum backoff time in milliseconds for the sync loop.
16+ */
17+ syncLoopMinBackoff ?: number ;
18+
19+ /**
20+ * Maximum backoff time in milliseconds for the sync loop.
21+ */
22+ syncLoopMaxBackoff ?: number ;
1323}
1424
1525export class ServerCrudLocalHistorySync {
26+ private syncLoopTimer : any = 0 ;
27+
1628 constructor (
1729 protected readonly opts : ServerCrudLocalHistorySyncOpts ,
1830 protected readonly core : ServerCrudLocalHistoryCore ,
1931 ) { }
2032
33+ public start ( ) : void {
34+
35+ }
36+
37+ public stop ( ) : void {
38+
39+ }
40+
2141 protected remoteTimeout ( ) : number {
2242 return this . opts . remoteTimeout ?? 5000 ;
2343 }
@@ -146,10 +166,28 @@ export class ServerCrudLocalHistorySync {
146166 }
147167 }
148168
149- public async * listDirty ( collection : string [ ] = [ 'sync' , 'dirty' ] ) : AsyncIterableIterator < { collection : string [ ] ; id : string } > {
169+ protected async * listDirty ( collection : string [ ] = [ 'sync' , 'dirty' ] ) : AsyncIterableIterator < { collection : string [ ] ; id : string } > {
150170 for await ( const entry of this . core . crud . scan ( collection ) ) {
151171 if ( entry . type === 'collection' ) yield * this . listDirty ( [ ...collection , entry . id ] ) ;
152172 else yield { collection, id : entry . id } ;
153173 }
154174 }
175+
176+ protected async * syncDirty ( ) : AsyncIterableIterator < [ block : { collection : string [ ] ; id : string } , success : boolean ] > {
177+ for await ( const block of this . listDirty ( ) ) {
178+ const { collection, id} = block ;
179+ const success = await this . push ( collection , id ) ;
180+ yield [ block , success ] ;
181+ }
182+ }
183+
184+ protected async syncAllDirty ( ) : Promise < SyncResultList > {
185+ const list : SyncResultList = [ ] ;
186+ for await ( const result of this . syncDirty ( ) ) list . push ( result ) ;
187+ return list ;
188+ }
155189}
190+
191+ export type ItemId = { collection : string [ ] , id : string } ;
192+ export type SyncResult = [ block : ItemId , success : boolean ] ;
193+ export type SyncResultList = SyncResult [ ] ;
0 commit comments