wait for sync from other peers

This commit is contained in:
Alexey Kasyanchuk 2018-04-17 23:25:58 +03:00
parent 675e133e1f
commit 9e2dbcc84b

View File

@ -17,7 +17,14 @@ module.exports = class P2PStore {
this.id = rows[0].mx + 1; this.id = rows[0].mx + 1;
console.log('store db index', this.id) console.log('store db index', this.id)
const syncTimeout = setInterval(() => {
if(this.p2p.size <= 0)
return
clearInterval(syncTimeout)
this.sync() this.sync()
}, 10000)
}) })
this.p2p.on('dbStore', (record, callback) => { this.p2p.on('dbStore', (record, callback) => {
@ -60,6 +67,7 @@ module.exports = class P2PStore {
sync() sync()
{ {
console.log('sync db on version', this.id)
this.p2p.emit('dbSync', {id: this.id}, (data) => { this.p2p.emit('dbSync', {id: this.id}, (data) => {
if(!data || !data.records) if(!data || !data.records)
return return