jeremyd/celluloid-websocket-client — pull request #12 by superquadratic (2013-12-05 10:33:02+00:00)
Title: Do Not Crash Actor When Connection is Closed

I'm using this `WebSocketActor` (see code below) that I want to close eventually. For it to work reliably, I have to catch `EOFError` in the parsing loop. That is because the loop sometimes keeps on reading from the socket when the connection is already closed, but the `on_close` handler has not been called yet.

I'm not sure if this is the right thing to do, but I'd like to put it up for discussion.

```ruby
class WebSocketActor
include Celluloid

def initialize(uri)
@client = Celluloid::WebSocket::Client.new(uri, current_actor)
end

def on_close(code, reason)
@client.terminate
terminate
end

def close
@client.close
end
end
```