From 0ec9133c213b2937b563589489cd899d4202a04d Mon Sep 17 00:00:00 2001 From: Hans Klunder Date: Tue, 6 May 2025 20:05:07 +0200 Subject: [PATCH 1/2] fix: replace waitForEvent() by once() --- abstract.js | 7 +++++-- promisified.js | 11 ++--------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/abstract.js b/abstract.js index b4e6962..db30629 100644 --- a/abstract.js +++ b/abstract.js @@ -1,5 +1,8 @@ +'use strict' + const Packet = require('aedes-packet') -const { PromisifiedPersistence, waitForEvent, getArrayFromStream } = require('./promisified.js') +const { once } = require('node:events') +const { PromisifiedPersistence, getArrayFromStream } = require('./promisified.js') // helper functions @@ -73,7 +76,7 @@ function abstractPersistence (opts) { // destroyed while it's still being set up. // https://github.com/mcollina/aedes-persistence-redis/issues/41 if (waitForReady && !instance.ready) { - await waitForEvent(instance, 'ready') + await once(instance, 'ready') } t.diagnostic('instance created') const prInstance = new PromisifiedPersistence(instance) diff --git a/promisified.js b/promisified.js index 98d08b1..372d800 100644 --- a/promisified.js +++ b/promisified.js @@ -1,6 +1,8 @@ // promisified versions of the persistence interface // to avoid deep callbacks while testing +'use strict' + class PromisifiedPersistence { constructor (instance) { this.instance = instance @@ -272,14 +274,6 @@ class PromisifiedPersistence { // end of promisified versions ofthis.instance methods // helper functions -function waitForEvent (obj, resolveEvt) { - return new Promise((resolve, reject) => { - obj.once(resolveEvt, () => { - resolve() - }) - obj.once('error', reject) - }) -} // stream.toArray() sometimes returns undefined or [undefined] instead of [] async function getArrayFromStream (stream) { @@ -294,6 +288,5 @@ async function getArrayFromStream (stream) { module.exports = { PromisifiedPersistence, - waitForEvent, getArrayFromStream } From 855b033a8676af606b75df8e41e4172b1cd22bc5 Mon Sep 17 00:00:00 2001 From: Hans Klunder Date: Wed, 7 May 2025 17:15:48 +0200 Subject: [PATCH 2/2] move strict up --- promisified.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/promisified.js b/promisified.js index 372d800..7f3de1b 100644 --- a/promisified.js +++ b/promisified.js @@ -1,8 +1,8 @@ +'use strict' + // promisified versions of the persistence interface // to avoid deep callbacks while testing -'use strict' - class PromisifiedPersistence { constructor (instance) { this.instance = instance