Created
February 16, 2010 21:31
-
-
Save joelash/305954 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
require "rubygems" | |
require "jretlang" | |
class Arnie | |
def initialize | |
@channel = JRL::Channel.new | |
@consumer = JRL::Fiber.new | |
end | |
def start | |
@consumer.start | |
@channel.subscribe_on_fiber( @consumer ) do |message| | |
case message | |
when "The End" | |
puts "I will be back..." | |
@consumer.dispose | |
@consumer.join | |
when "Terminate" | |
puts "Hastala vista baby!!!" | |
else | |
puts "You are terminated******" | |
end | |
end | |
end | |
def ^(message) | |
@channel.publish(message) | |
end | |
end | |
terminator = Arnie.new | |
terminator.start | |
terminator ^ "Terminate" | |
terminator ^ "Buy me ice cream" | |
terminator ^ "The End" | |
terminator ^ "Terminate" |
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 "rubygems" | |
require "jretlang" | |
class Arnie | |
def initialize | |
@consumer = JRL::Fiber.new | |
end | |
def start | |
@consumer.start | |
end | |
def ^(message) | |
@consumer.execute do | |
case message | |
when "The End" | |
puts "I will be back..." | |
@consumer.dispose | |
@consumer.join | |
when "Terminate" | |
puts "Hastala vista baby!!!" | |
else | |
puts "You are terminated******" | |
end | |
end | |
end | |
end | |
terminator = Arnie.new | |
terminator.start | |
terminator ^ "Terminate" | |
terminator ^ "Buy me ice cream" | |
terminator ^ "The End" | |
terminator ^ "Terminate" |
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 "rubygems" | |
require "mailbox" | |
class Arnie | |
include Mailbox | |
mailslot | |
def ^(message) | |
case message | |
when "The End" | |
puts "I will be back..." | |
# cannot dispose from here | |
when "Terminate" | |
puts "Hastala vista baby!!!" | |
else | |
puts "You are terminated******" | |
end | |
end | |
end | |
terminator = Arnie.new | |
terminator ^ "Terminate" | |
terminator ^ "Buy me ice cream" | |
terminator ^ "The End" | |
terminator ^ "Terminate" # THIS STILL PRINTS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment