Skip to content

Commit 0cdf4e2

Browse files
authored
fix: make setup() in callBackPersistence async (#106)
* fix: make callback setup() async * add test to verify that .setup() is async
1 parent 9528bd4 commit 0cdf4e2

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

abstract.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ function abstractPersistence (opts) {
173173
}
174174

175175
// testing starts here
176+
test('verify setup() method is async', async t => {
177+
t.plan(1)
178+
const prInstance = await persistence(t)
179+
t.assert.equal(prInstance.setup.constructor.name, 'AsyncFunction', '.setup() must be an async function')
180+
})
181+
176182
test('store and look up retained messages', async t => {
177183
t.plan(1)
178184
await matchRetainedWithPattern(t, 'hello/world')

callBackPersistence.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ class CallBackPersistence extends EventEmitter {
1717
}
1818

1919
set broker (broker) {
20-
this.setup(broker)
21-
}
22-
23-
setup (broker) {
2420
if (this.ready) {
2521
return
2622
}
@@ -35,6 +31,10 @@ class CallBackPersistence extends EventEmitter {
3531
})
3632
}
3733

34+
async setup (broker) {
35+
return this.asyncPersistence.setup(broker)
36+
}
37+
3838
subscriptionsByTopic (topic, cb) {
3939
if (cb) {
4040
if (!this.ready) {

0 commit comments

Comments
 (0)