From 4142fa34b848923590228f5af9e791adb71cdbd3 Mon Sep 17 00:00:00 2001 From: Christophe Diederichs <45171645+chm-diederichs@users.noreply.github.com> Date: Thu, 13 Apr 2023 12:00:39 +0100 Subject: [PATCH] Readd heads to linearizer on restart (#53) * readd heads to linearizer on restart * fix bad copy --- index.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 3fdd748c..ec774f33 100644 --- a/index.js +++ b/index.js @@ -402,6 +402,23 @@ module.exports = class Autobase extends ReadyResource { this._undo(this._updates.length) await this._cleanup() + await this._addHeads() + } + + async _addHeads () { + let active = true + + while (active) { + await this._ensureAll() + + active = false + for (const w of this.writers) { + if (!w.next) continue + this.linearizer.addHead(w.advance()) + active = true + break + } + } } async _advance () { @@ -419,19 +436,7 @@ module.exports = class Autobase extends ReadyResource { } } - let active = true - - while (active) { - await this._ensureAll() - - active = false - for (const w of this.writers) { - if (!w.next) continue - this.linearizer.addHead(w.advance()) - active = true - break - } - } + await this._addHeads() const u = this.linearizer.update() const needsRestart = u ? await this._applyUpdate(u) : false