-
-
Save halorgium/5404407 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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