Skip to content

Commit

Permalink
sync start simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
LiranCohen committed Sep 4, 2024
1 parent 4d95c0c commit b5a9a2b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/agent/src/sync-engine-level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,20 @@ export class SyncEngineLevel implements SyncEngine {
}
}

public startSync({ interval }: {
public async startSync({ interval }: {
interval: string
}): Promise<void> {
// Convert the interval string to milliseconds.
const intervalMilliseconds = ms(interval);

if (this._syncIntervalId) {
this.stopSync();
}

if (!this._syncLock) {
await this.sync();
}

return new Promise((resolve, reject) => {
const intervalSync = async () => {
if (this._syncLock) {
Expand All @@ -317,10 +325,6 @@ export class SyncEngineLevel implements SyncEngine {
}
};

if (this._syncIntervalId) {
clearInterval(this._syncIntervalId);
}

this._syncIntervalId = setInterval(intervalSync, intervalMilliseconds);
});
}
Expand Down

0 comments on commit b5a9a2b

Please sign in to comment.