Created
September 27, 2012 00:29
-
-
Save e0da/3791473 to your computer and use it in GitHub Desktop.
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
class Actor | |
def ping | |
puts "#{self.class.name}:ping" | |
end | |
end | |
class SinatraApp < Actor | |
def run | |
loop do | |
puts :whoa? | |
sleep 2 | |
end | |
end | |
end | |
class BigBrother < Actor | |
def run | |
loop do | |
puts :whee | |
sleep 3 | |
end | |
end | |
end | |
class Runner | |
def initialize | |
@sinatra = SinatraApp.new | |
@big_brother = BigBrother.new | |
@threads = [] | |
@threads << Thread.new { @sinatra.run } | |
@threads << Thread.new { @big_brother.run } | |
@threads << Thread.new { monitor } | |
@threads.each {|t| t.join} | |
end | |
def monitor | |
loop do | |
@sinatra.ping | |
@big_brother.ping | |
sleep 1 | |
end | |
end | |
end | |
Runner.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment