From f2aa6b550a40f0acd7712e17b6f75a231d4763a5 Mon Sep 17 00:00:00 2001 From: MKPLKN <15703708+MKPLKN@users.noreply.github.com> Date: Fri, 6 Sep 2024 13:57:31 +0300 Subject: [PATCH] Remove monitor from the Set on close --- lib/monitor.js | 1 + test.js | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/monitor.js b/lib/monitor.js index 47cd01a..4eee778 100644 --- a/lib/monitor.js +++ b/lib/monitor.js @@ -50,6 +50,7 @@ module.exports = class Monitor extends ReadyResource { this.blobs.core.off('append', this._boundOnAppend) this.blobs.core.off('upload', this._boundOnUpload) this.blobs.core.off('download', this._boundOnDownload) + this.drive.monitors.delete(this) } async _onAppend () { diff --git a/test.js b/test.js index b748ddf..cb4d860 100644 --- a/test.js +++ b/test.js @@ -1615,6 +1615,15 @@ test('upload/download can be monitored', async (t) => { await mirror.drive.get(file) }) +test('monitor is removed from the Set on close', async (t) => { + const { drive } = await testenv(t.teardown) + const monitor = drive.monitor('/example.md') + await monitor.ready() + t.is(drive.monitors.size, 1) + await monitor.close() + t.is(drive.monitors.size, 0) +}) + async function testenv (teardown) { const corestore = new Corestore(RAM) await corestore.ready()