Created
November 29, 2011 23:41
-
-
Save ox/1407183 to your computer and use it in GitHub Desktop.
A better Ping-Pong example using Actors in Rubinius2.0.0dev. Ends only when you press enter or something
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 'actor' | |
Ping = Struct.new :sender | |
Pong = Struct.new :sender | |
Actor.spawn do | |
Actor.register(:ping, Actor.current) | |
loop do | |
Actor.receive do |msg| | |
msg.when(Ping) do |p| | |
puts "ping" | |
p.sender << Pong.new(Actor.current) | |
end | |
end | |
end | |
end | |
Actor.spawn do | |
Actor[:ping] << Ping.new(Actor.current) | |
loop do | |
Actor.receive do |msg| | |
msg.when(Pong) do |p| | |
puts "pong" | |
p.sender << Ping.new(Actor.current) | |
end | |
end | |
end | |
end | |
gets |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment