From df4ce84ae311222ae7bb53c60558baa932195936 Mon Sep 17 00:00:00 2001 From: Christophe Diederichs <45171645+chm-diederichs@users.noreply.github.com> Date: Wed, 25 Sep 2024 13:27:16 +0200 Subject: [PATCH] watcher async iterator must exit on close (#165) * watcher async iterator must exit on close * resolve on change if closing --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f7155da..bb86a95 100644 --- a/index.js +++ b/index.js @@ -1262,7 +1262,7 @@ class Watcher extends ReadyResource { _onappend () { // TODO: this is a light hack / fix for non-sparse session reporting .length's inside batches // the better solution is propably just to change non-sparse sessions to not report a fake length - if (!this.core.isAutobase && (!this.core.core || this.core.core.tree.length !== this.core.length)) return + if (!this.closing && !this.core.isAutobase && (!this.core.core || this.core.core.tree.length !== this.core.length)) return const resolve = this._resolveOnChange this._resolveOnChange = null @@ -1298,6 +1298,8 @@ class Watcher extends ReadyResource { while (true) { await this._waitForChanges() + if (this.closing) return { value: undefined, done: true } + if (this._updateOnce) { this._updateOnce = false await this.bee.update({ wait: true })