Skip to content

Instantly share code, notes, and snippets.

@halorgium
Forked from romansergey/Gemfile
Last active December 16, 2015 08:18
Show Gist options
  • Save halorgium/5404407 to your computer and use it in GitHub Desktop.
Save halorgium/5404407 to your computer and use it in GitHub Desktop.
source 'https://rubygems.org'
gem 'celluloid-io', :git => 'https://github.com/celluloid/celluloid-io.git'
gem 'celluloid', :git => 'https://github.com/celluloid/celluloid.git'
gem 'reel',:git => 'https://github.com/celluloid/reel.git'
require 'reel'
require 'test_actor'
class MyServer < Reel::Server
def initialize(host = "127.0.0.1", port = 3000)
@actor_pool = TestActor.pool(size: 2)
# or:
# @actor_pool = TestActor.new
# to reproduce https://github.com/celluloid/celluloid-io/issues/46
super(host, port, &method(:on_connection))
end
def on_connection(connection)
while request = connection.request
case request
when Reel::Request
connection.detach
handle_request(request)
when Reel::WebSocket
handle_websocket(request)
end
end
end
def handle_request(request)
@actor_pool.fire do |response|
request.respond :ok, response
end
end
def handle_websocket(sock)
sock << "Hello everyone out there in WebSocket land!"
sock.close
end
end
puts "Starting server..."
MyServer.run
require 'celluloid'
class TestActor
include Celluloid
def fire
yield "The time on my actor #{Thread.current.inspect} is #{Time.now}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment