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

Expose socket events #1

Merged
merged 2 commits into from
Mar 6, 2019
Merged

Expose socket events #1

merged 2 commits into from
Mar 6, 2019

Conversation

kenhunt
Copy link

@kenhunt kenhunt commented Mar 6, 2019

A few updates:
- Implements the peek-buried operation.
- The connect() promise rejects if connection can't be made.
- Adds support for listening to key socket events to enable reconnect logic.
- Adds isConnected() operation so that consumers don't need to wrap the client just
to determine when the client has lost connection.

Ken Hunt added 2 commits March 5, 2019 17:56
 - Implements the peek-buried operation.
 - The connect() promise rejects if connection can't be made.
 - Adds support for listening to key socket events to enable reconnect logic.
 - Adds isConnected() operation so that consumers don't need to wrap the client just
 to determine when the client has lost connection.
@kenhunt kenhunt requested a review from ruffrey March 6, 2019 00:19
* @param listener
*/
JackdClient.prototype.on = function(event, listener) {
if (SOCKET_EVENTS.includes(event)) {
Copy link
Member

Choose a reason for hiding this comment

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

The way this is written, JackdClient could never be an eventemitter on it's own. Not sure that is a problem or not.

Copy link
Author

Choose a reason for hiding this comment

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

It uses an emitter internally to trigger the callbacks passed in (see the createCommandHandler pattern used throughout). But it wasn't emitting those to consumers as there was no .on() function available to register.

I originally planned to allow consumers to the internal emitter (which is why I accidentally left in the SOCKET_EVENTS array and check) but I decided that was needless scope creep. And the check for 'if (SOCKET_EVENTS.includes(event)) {' doesn't hurt anything.

Copy link
Member

Choose a reason for hiding this comment

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

After going back through the original code, I think that makes sense. Seems simpler to use callbacks in this case than exposing the eventemitter.

src/index.js Show resolved Hide resolved
@kenhunt kenhunt merged commit 6535d2e into master Mar 6, 2019
ruffrey pushed a commit that referenced this pull request Mar 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants