Skip to content

Commit 43591af

Browse files
committed
make recovery api public
1 parent 2a7ab69 commit 43591af

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,10 +627,19 @@ class Hypercore extends EventEmitter {
627627
return this.opened === false ? null : this.core.globalCache
628628
}
629629

630+
get recovering() {
631+
return this.opened === false ? 0 : this.core.header.hints.recovering
632+
}
633+
630634
ready() {
631635
return this.opening
632636
}
633637

638+
async recover() {
639+
if (this.opened === false) await this.opening
640+
return this.state.waitForRecovery()
641+
}
642+
634643
async setUserData(key, value) {
635644
if (this.opened === false) await this.opening
636645
const existing = await this.getUserData(key)

lib/session-state.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ module.exports = class SessionState {
569569
}
570570

571571
// simple tool to wait for other peers to catch us up
572-
async _waitForRecovery() {
572+
async waitForRecovery() {
573573
const length = this.length
574574
const replicator = this.core.replicator
575575

@@ -607,7 +607,7 @@ module.exports = class SessionState {
607607
async append(values, { signature, keyPair, preappend, postappend, maxLength = -1 } = {}) {
608608
if (!keyPair && this.isDefault()) keyPair = this.core.header.keyPair
609609

610-
if (this.isDefault() && this.core.header.hints.recovering) await this._waitForRecovery()
610+
if (this.isDefault() && this.core.header.hints.recovering) await this.waitForRecovery()
611611

612612
await this.mutex.lock()
613613

@@ -965,7 +965,7 @@ module.exports = class SessionState {
965965
throw ASSERTION('Cannot commit while repair mode is on')
966966
}
967967

968-
if (this.core.header.hints.recovering) await this._waitForRecovery()
968+
if (this.core.header.hints.recovering) await this.waitForRecovery()
969969

970970
let srcLocked = false
971971
await this.mutex.lock()

0 commit comments

Comments
 (0)