Skip to content

Commit

Permalink
Sync constructor (#591)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Nov 12, 2024
1 parent de5520e commit 161a69d
Show file tree
Hide file tree
Showing 21 changed files with 606 additions and 1,551 deletions.
520 changes: 147 additions & 373 deletions index.js

Large diffs are not rendered by default.

431 changes: 0 additions & 431 deletions lib/batch.js

This file was deleted.

5 changes: 3 additions & 2 deletions lib/copy-prologue.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const crypto = require('hypercore-crypto')
const flat = require('flat-tree')
const b4a = require('b4a')
const quickbit = require('quickbit-universal')
Expand Down Expand Up @@ -89,7 +90,7 @@ async function flushBatch (prologue, src, dst, batch) {
// reads done!

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

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

function prologueToTree (prologue) {
Expand Down
Loading

0 comments on commit 161a69d

Please sign in to comment.