Skip to content

Commit f1feb12

Browse files
authored
only emit post flush (#782)
* only emit post flush * fix missing var * add telamohn test
1 parent 16dc8af commit f1feb12

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

lib/core.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ module.exports = class Core {
5555
this.closed = false
5656

5757
this.hintsChanged = false
58+
this.remoteContiguousLengthChanged = false
5859

5960
this._bitfield = null
6061
this._verifies = null
@@ -86,6 +87,17 @@ module.exports = class Core {
8687
s._monitorIndex = -1
8788
}
8889

90+
emitRemoteContiguousLength() {
91+
if (!this.remoteContiguousLengthChanged) return
92+
this.remoteContiguousLengthChanged = false
93+
94+
const length = this.header.hints.remoteContiguousLength
95+
96+
for (let i = this.monitors.length - 1; i >= 0; i--) {
97+
this.monitors[i].emit('remote-contiguous-length', length)
98+
}
99+
}
100+
89101
emitManifest() {
90102
for (let i = this.monitors.length - 1; i >= 0; i--) {
91103
this.monitors[i].emit('manifest')
@@ -819,10 +831,7 @@ module.exports = class Core {
819831
updateRemoteContiguousLength(length) {
820832
this.header.hints.remoteContiguousLength = length
821833
this.hintsChanged = true
822-
823-
for (let i = this.monitors.length - 1; i >= 0; i--) {
824-
this.monitors[i].emit('remote-contiguous-length', length)
825-
}
834+
this.remoteContiguousLengthChanged = true
826835
}
827836

828837
onappend(tree, bitfield) {

lib/replicator.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,8 @@ class Peer {
14341434

14351435
if (this.core.hintsChanged) await this.core.flushHints()
14361436
if (drop === false) this._update()
1437+
1438+
this.core.emitRemoteContiguousLength()
14371439
}
14381440

14391441
onreorghint() {

test/snapshots.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,19 @@ test('error when using inconsistent snapshot', async function (t) {
262262
await snapshot.close()
263263
await core.close()
264264
})
265+
266+
test('snapshot works with an active atomized session without persisted dependency state', async function (t) {
267+
const core = await create(t)
268+
const atom = core.state.storage.createAtom()
269+
const atomic = core.session({ atom })
270+
271+
await atomic.ready()
272+
273+
const snap = core.snapshot()
274+
await snap.ready()
275+
276+
t.is(snap.length, 0, 'snapshot opened successfully')
277+
278+
await snap.close()
279+
await atomic.close()
280+
})

0 commit comments

Comments
 (0)