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

self is dropped in the callbacks #21

Open
sergeych opened this issue Jun 22, 2016 · 4 comments
Open

self is dropped in the callbacks #21

sergeych opened this issue Jun 22, 2016 · 4 comments

Comments

@sergeych
Copy link

It is actually a bug in the eventemitter gem, and serious one. Event callbacks for the socket are called on the wrong context, set by the emitter. It took me several hours to trace. I suggest to fix emitter or refrain of using it.

Sample:
`
me = self
@ws = WebSocket::Client::Simple.connect(ws_url)

@ws.on(:open) {
if me != self
puts "\n\n\nSelf is set to wrong in the callback in #{RUBY_VERSION}\n\n\n"
end
}
`

@SpComb
Copy link

SpComb commented May 31, 2017

Workaround is to set a base = self local, and then use base.foo in the callback blocks.

@sergeych
Copy link
Author

sure. but first you somehow need to know the problem exists, it is not what you expect from a ruby code. I once lost 4 hours struggling to cope with the same bug in early rails...

@Xasin
Copy link

Xasin commented Feb 22, 2018

Dang, the same issue just got me.
I was just about to get annoyed at this gem for manipulating self, but if it's a bug from a different gem ...

Thank you for the fix suggestion! That is a really annoying bug though.

@unasuke
Copy link
Contributor

unasuke commented Dec 30, 2021

@sergeych This repository was moved ruby-jp/websocket-client-simple. If you still need this, make pull request or issue to ruby-jp/websocket-client-simple again, thx.

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

4 participants