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

on vs bind #7

Open
RobertLowe opened this issue Jun 7, 2021 · 2 comments
Open

on vs bind #7

RobertLowe opened this issue Jun 7, 2021 · 2 comments

Comments

@RobertLowe
Copy link

It's odd that Socket inherits from EventEmitter but implements its own event cycle with bind

https://github.com/bcoin-org/bsock/blob/master/lib/socket.js#L19

https://github.com/bcoin-org/bsock/blob/master/lib/socket.js#L837-L887

I raise this issue because I was mistakenly using on and not bind so events we're firing, but there is something odd about the implementation as such, its managing two lifecycles one on the Socket, one internally on Events.

Perhaps as a solution, on could proxy to bind when sensible to maintain a consistent event emitter implementation

@pinheadmz
Copy link
Member

Good question, I notice the implementation for bind and hook have blacklist checks -- it could simply be that @chjj wanted to protect the event emitter in applicaitons like bcoin and hsd.

@RobertLowe
Copy link
Author

My guess is it to differentiate some Socket events and the internal events. That said, I don't see how a blacklist really provides any benefit here. Thanks

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

No branches or pull requests

2 participants