Skip to content

Commit

Permalink
fix: Can await returned client (#17)
Browse files Browse the repository at this point in the history
calling `await client` was throwing an error. The returned client should
not be thenable, and should just return the same client
  • Loading branch information
gmaclennan authored Sep 18, 2023
1 parent 3cbcc1d commit 7451dc3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ function createClient(channel, { timeout = 5000 } = {}) {
// }
if (typeof prop !== 'string') {
throw new Error(`ReferenceError: ${String(prop)} is not defined`)
} else if (prop === 'then') {
return null
} else if (prop in EventEmitter.prototype) {
const eventEmitterProp = /** @type {keyof EventEmitter} */ (prop)
if (emitterSubscribeMethods.includes(eventEmitterProp)) {
Expand Down
7 changes: 7 additions & 0 deletions test/e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,4 +550,11 @@ function runTests(setup) {
t.doesNotThrow(() => console.log(client.add(1, 2)))
t.end()
})

test('Can await client', async (t) => {
const { client } = setup(myApi)
const awaited = await client
t.is(awaited, client, 'Same object is returned when awaiting')
t.end()
})
}

0 comments on commit 7451dc3

Please sign in to comment.