From 9e2dbcc84bcb5f2b7a4b176f891ed45788ccfcac Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Tue, 17 Apr 2018 23:25:58 +0300 Subject: [PATCH] wait for sync from other peers --- src/background/store.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/background/store.js b/src/background/store.js index 2d025fd..510a327 100644 --- a/src/background/store.js +++ b/src/background/store.js @@ -17,7 +17,14 @@ module.exports = class P2PStore { this.id = rows[0].mx + 1; console.log('store db index', this.id) - this.sync() + + const syncTimeout = setInterval(() => { + if(this.p2p.size <= 0) + return + + clearInterval(syncTimeout) + this.sync() + }, 10000) }) this.p2p.on('dbStore', (record, callback) => { @@ -60,6 +67,7 @@ module.exports = class P2PStore { sync() { + console.log('sync db on version', this.id) this.p2p.emit('dbSync', {id: this.id}, (data) => { if(!data || !data.records) return