Skip to content

Instantly share code, notes, and snippets.

@rakvat
Created June 4, 2014 20:38
Show Gist options
  • Save rakvat/b0ff391fdd531873c8f6 to your computer and use it in GitHub Desktop.
Save rakvat/b0ff391fdd531873c8f6 to your computer and use it in GitHub Desktop.
reel server example that crashes when client is killed (https://github.com/celluloid/reel/issues/150)
require 'reel'
#0.4.0
#class MyServer < Reel::Server
#0.5.0
class MyServer < Reel::Server::HTTP
def initialize(host = "127.0.0.1", port = 3000)
super(host, port, &method(:on_connection))
end
def on_connection(connection)
# crashes in next line with
# "Reel::StateError: already processing a request"
connection.each_request do |request|
# does not help: request.body.to_str
if request.websocket?
else
handle_request(request)
end
end
end
def handle_request(request)
# do some work
x=0
(1..100000).to_a.each do |i|
x+=i*i
end
#response
request.respond :ok, "Hello, world #{x}!"
end
end
MyServer.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment