@lunarislab/state-sync 1.1.16 → 1.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/classes/Syncer.js +5 -9
- package/package.json +1 -1
package/classes/Syncer.js
CHANGED
@@ -23,26 +23,22 @@ class Syncer extends SimpleEmitter_1.SimpleEmitter {
|
|
23
23
|
}
|
24
24
|
;
|
25
25
|
async _commit() {
|
26
|
-
const date = Date.now();
|
27
|
-
// If the last push was less than "commitInterval" ago, don't commit
|
28
|
-
if (this.lastPush > date - this.commitInterval)
|
29
|
-
return;
|
30
|
-
this.lastPush = date;
|
31
|
-
// Wait for commit interval to avoid letting some logs in the queue
|
32
|
-
await new Promise(x => setTimeout(x, this.commitInterval));
|
33
|
-
// Clear queue and save logs
|
34
26
|
const logs = this.logs.splice(0, this.logs.length);
|
35
27
|
const commits = await this.saver.saveLogs(logs);
|
36
28
|
this.emit("commit", { commits });
|
29
|
+
// start the recursive commit process
|
30
|
+
await new Promise(x => setTimeout(x, this.commitInterval));
|
31
|
+
this._commit();
|
37
32
|
}
|
33
|
+
;
|
38
34
|
async start() {
|
39
35
|
await this.saver.init();
|
40
36
|
this.watcher.on('log', async (log) => {
|
41
37
|
this.emit('log', { log: log });
|
42
38
|
this.logs.push(log);
|
43
|
-
await this._commit();
|
44
39
|
});
|
45
40
|
await this.watcher.start();
|
41
|
+
this._commit();
|
46
42
|
}
|
47
43
|
;
|
48
44
|
async addContracts(contracts) {
|