Skip to content

Commit 161a69d

Browse files
Sync constructor (#591)
* wip * checkpoint * tests pass now * add safe close api on core and move replicator there * more stuff in core * all hooks live in core * inline replicator * premerge * no need to skip * add static helper for making core cores * bye bye non-sparse mode * Core manages replicator lifecycle (#592) * state unref is sync * core closes storage * replicator no longer needs session * remove force close from session * fix bad condition * core being set is invariant * remove stale method * query sessions on underlying core * move autoClose onto Core * rename close to destroy * core destroys state * preload is now simply a promise * preload promise can return opts * no need to check if state is active * add onidle hook * idle waits for mutex to be free also * remove from option * exclusive sessions * always emit close * fix test * pass userdata to create for atomicity * core always refs default state * session explicitly refs state --------- Co-authored-by: Christophe Diederichs <[email protected]> Co-authored-by: Christophe Diederichs <[email protected]>
1 parent de5520e commit 161a69d

21 files changed

+606
-1551
lines changed

index.js

Lines changed: 147 additions & 373 deletions
Large diffs are not rendered by default.

lib/batch.js

Lines changed: 0 additions & 431 deletions
This file was deleted.

lib/copy-prologue.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const crypto = require('hypercore-crypto')
12
const flat = require('flat-tree')
23
const b4a = require('b4a')
34
const quickbit = require('quickbit-universal')
@@ -89,7 +90,7 @@ async function flushBatch (prologue, src, dst, batch) {
8990
// reads done!
9091

9192
if (batch.first) {
92-
const treeHash = dst.crypto.tree(nodes.slice(0, batch.roots.length))
93+
const treeHash = crypto.tree(nodes.slice(0, batch.roots.length))
9394
if (!b4a.equals(treeHash, prologue.hash)) throw new Error('Prologue does not match source')
9495
}
9596

@@ -178,7 +179,7 @@ async function flushBatch (prologue, src, dst, batch) {
178179
function signalReplicator (core, upgraded, start, length) {
179180
const status = upgraded ? 0b0011 : 0b0010
180181
const bitfield = { drop: false, start, length }
181-
core.onupdate({ status, bitfield, value: null, from: null })
182+
core._onupdate({ status, bitfield, value: null, from: null })
182183
}
183184

184185
function prologueToTree (prologue) {

0 commit comments

Comments
 (0)