-
Notifications
You must be signed in to change notification settings - Fork 49
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
updated: docs, test, source #11
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for the PR!
One thing that this is missing is that the async methods need to pass callbacks to the actual functions from the client.
When you use Promise.resolve() you're creating a new promise that immediately resolves to undefined
since the client's methods expect a callback to be passed in.
Would you mind adding the additional logic from defineAsync
where we had makeCallback
added to the argument list before passing it to the client's methods?
index.js
Outdated
ASYNC_METHODS.forEach(defineAsync); | ||
SYNC_METHODS.forEach(definePassthrough); | ||
async publish (...args) { | ||
return this._client.publish(...args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still isn't passing a callback to the client. It should look something like this:
return this._client.publish(...args); | |
return new Promise((resolve, reject) => { | |
this._client.publish(...args, (err, result) => { | |
if(err) reject(err) | |
else resolve(result) | |
}) | |
}) |
This will return a promise that only resolves once the publish has been acknowledged by the broker, or will reject if there was a problem.
Without this wrapper, it'd be resolving immediately and the potential error would never be handled.
This should be done with all the async methods.
Nice, it's looking good to me. 😀 I'll do some manual testing later this week and then get this released as a major update. Thanks again! |
Thanks again for the PR! I've released it in 2.2.0 |
No description provided.