wait for sync from other peers
This commit is contained in:
parent
675e133e1f
commit
9e2dbcc84b
@ -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)
|
||||||
this.sync()
|
|
||||||
|
const syncTimeout = setInterval(() => {
|
||||||
|
if(this.p2p.size <= 0)
|
||||||
|
return
|
||||||
|
|
||||||
|
clearInterval(syncTimeout)
|
||||||
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user