Created
November 5, 2012 15:00
-
-
Save danielsz/4017605 to your computer and use it in GitHub Desktop.
Concurrent Hello world in ruby with Celluloid, an actor library
This file contains hidden or 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 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