Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions abstract.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
Expand Down
11 changes: 2 additions & 9 deletions promisified.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// promisified versions of the persistence interface
// to avoid deep callbacks while testing

'use strict'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be placed as really first line


class PromisifiedPersistence {
constructor (instance) {
this.instance = instance
Expand Down Expand Up @@ -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) {
Expand All @@ -294,6 +288,5 @@ async function getArrayFromStream (stream) {

module.exports = {
PromisifiedPersistence,
waitForEvent,
getArrayFromStream
}