Skip to content

Commit

Permalink
emit state changes post drain loop
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Sep 25, 2024
1 parent ad8f947 commit c21b061
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,6 @@ module.exports = class Autobase extends ReadyResource {
_setLocalWriter (w) {
this.localWriter = w
if (this._ackInterval) this._startAckTimer()
this.emit('writable')
}

_unsetLocalWriter () {
Expand All @@ -1149,8 +1148,6 @@ module.exports = class Autobase extends ReadyResource {
if (this.localWriter.isActiveIndexer) this._clearLocalIndexer()

this.localWriter = null

this.emit('unwritable')
}

_setLocalIndexer () {
Expand Down Expand Up @@ -1267,6 +1264,8 @@ module.exports = class Autobase extends ReadyResource {
}

async _drain () {
const writable = this.writable

while (!this._interrupting && !this.paused) {
if (this.opened && this.fastForwardTo !== null) {
await this._applyFastForward()
Expand Down Expand Up @@ -1330,6 +1329,9 @@ module.exports = class Autobase extends ReadyResource {
await this._gcWriters()
await this._reindex()
}

// emit state changes post drain
if (writable !== this.writable) this.emit(writable ? 'unwritable' : 'writable')
}

progress () {
Expand Down

0 comments on commit c21b061

Please sign in to comment.