Skip to content

Commit

Permalink
wakeup add is now async because of user data api
Browse files Browse the repository at this point in the history
  • Loading branch information
chm-diederichs committed Nov 27, 2024
1 parent 0669fcc commit 8b89b50
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lib/wakeup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const b4a = require('b4a')
const c = require('compact-encoding')
const safetyCatch = require('safety-catch')
const ReadyResource = require('ready-resource')

const WakeupEntry = {
Expand Down Expand Up @@ -143,18 +144,17 @@ module.exports = class AutoWakeup extends ReadyResource {

add (core) {
if (core.writable || !core.opened) return // no need to track local cores...
return this._add(core)
return this._add(core).catch(safetyCatch)
}

remove (core) {
return this._remove(core)
}

_add (core) {
const userData = core.header.userData // unsafe but sync so much less race-condition-ey
async _add (core) {
let referrer = null

for (const { key, value } of userData) {
for await (const { key, value } of core.getUserData()) {
if (key === 'referrer') referrer = value
else if (key === 'autobase/view') return false
}
Expand Down
2 changes: 1 addition & 1 deletion lib/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module.exports = class Writer extends ReadyResource {
this.recover = autoRecover(this.core)

// add it again incase it wasn't readied before, only needed if this is the first time we set the referrer...
this.base._wakeup.add(this.core.core)
await this.base._wakeup.add(this.core.core)
}

// in case we are in the middle of a migration we might need to old sigs to reach threshold on the new cores
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"core-coupler": "^1.0.0",
"debounceify": "^1.0.0",
"hyperbee": "^2.15.0",
"hypercore": "github:holepunchto/hypercore#rocksdb-memory-view",
"hypercore": "github:holepunchto/hypercore#rocksdb-user-data",
"hypercore-crypto": "^3.4.0",
"hypercore-id-encoding": "^1.2.0",
"mutexify": "^1.4.0",
Expand All @@ -50,7 +50,7 @@
"devDependencies": {
"autobase-test-helpers": "^2.0.1",
"brittle": "^3.1.1",
"corestore": "github:holepunchto/corestore#v7-memory-view",
"corestore": "github:holepunchto/corestore#v7",
"rache": "^1.0.0",
"random-access-memory": "^6.2.0",
"same-data": "^1.0.0",
Expand Down

0 comments on commit 8b89b50

Please sign in to comment.