hypercore 11.27.1 → 11.27.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +9 -0
- package/lib/session-state.js +3 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -627,10 +627,19 @@ class Hypercore extends EventEmitter {
|
|
|
627
627
|
return this.opened === false ? null : this.core.globalCache
|
|
628
628
|
}
|
|
629
629
|
|
|
630
|
+
get recovering() {
|
|
631
|
+
return this.opened === false ? 0 : this.core.header.hints.recovering
|
|
632
|
+
}
|
|
633
|
+
|
|
630
634
|
ready() {
|
|
631
635
|
return this.opening
|
|
632
636
|
}
|
|
633
637
|
|
|
638
|
+
async recover() {
|
|
639
|
+
if (this.opened === false) await this.opening
|
|
640
|
+
return this.state.waitForRecovery()
|
|
641
|
+
}
|
|
642
|
+
|
|
634
643
|
async setUserData(key, value) {
|
|
635
644
|
if (this.opened === false) await this.opening
|
|
636
645
|
const existing = await this.getUserData(key)
|
package/lib/session-state.js
CHANGED
|
@@ -569,7 +569,7 @@ module.exports = class SessionState {
|
|
|
569
569
|
}
|
|
570
570
|
|
|
571
571
|
// simple tool to wait for other peers to catch us up
|
|
572
|
-
async
|
|
572
|
+
async waitForRecovery() {
|
|
573
573
|
const length = this.length
|
|
574
574
|
const replicator = this.core.replicator
|
|
575
575
|
|
|
@@ -607,7 +607,7 @@ module.exports = class SessionState {
|
|
|
607
607
|
async append(values, { signature, keyPair, preappend, postappend, maxLength = -1 } = {}) {
|
|
608
608
|
if (!keyPair && this.isDefault()) keyPair = this.core.header.keyPair
|
|
609
609
|
|
|
610
|
-
if (this.isDefault() && this.core.header.hints.recovering) await this.
|
|
610
|
+
if (this.isDefault() && this.core.header.hints.recovering) await this.waitForRecovery()
|
|
611
611
|
|
|
612
612
|
await this.mutex.lock()
|
|
613
613
|
|
|
@@ -965,7 +965,7 @@ module.exports = class SessionState {
|
|
|
965
965
|
throw ASSERTION('Cannot commit while repair mode is on')
|
|
966
966
|
}
|
|
967
967
|
|
|
968
|
-
if (this.core.header.hints.recovering) await this.
|
|
968
|
+
if (this.core.header.hints.recovering) await this.waitForRecovery()
|
|
969
969
|
|
|
970
970
|
let srcLocked = false
|
|
971
971
|
await this.mutex.lock()
|