Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TypeError: this.queue.close is not a function #93

Merged
merged 4 commits into from
Dec 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion lib/subscriber.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ class SubscriptionContext {
}

close () {
this.queue.close()
// In rare cases when `subscribe()` not called (e.g. some network error)
// `close` will be `undefined`.
if (typeof this.queue.close === 'function') {
this.queue.close()
mcollina marked this conversation as resolved.
Show resolved Hide resolved
}
this.queue.destroy()
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/subscriber.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ test('subscriber published an event', async (t) => {
})
})

test('subscription context not throw error on close', t => {
t.plan(1)
const pubsub = new PubSub(mq())

const sc = new SubscriptionContext({ pubsub })

sc.close()
t.pass()
})

test('subscription context publish event returns a promise', t => {
t.plan(1)
const pubsub = new PubSub(mq())
Expand Down