Skip to content

Instantly share code, notes, and snippets.

@danielsz
Created November 5, 2012 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielsz/4017605 to your computer and use it in GitHub Desktop.
Save danielsz/4017605 to your computer and use it in GitHub Desktop.
Concurrent Hello world in ruby with Celluloid, an actor library
require 'celluloid'
class Hello
include Celluloid
def say_hello
"hello"
end
end
class World
include Celluloid
def initialize
wait_for_hello!
end
def say_world
"world"
end
def wait_for_hello
loop do
message = receive { |msg| msg.is_a? String }
puts "#{message} #{say_world}"
end
end
end
hello = Hello.new
world = World.new
100.times do
world.mailbox << hello.say_hello
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment