/ Published in: Ruby
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
require "java" require "jetlang-0.2.0.jar" include_class "org.jetlang.fibers.ThreadFiber" include_class "org.jetlang.channels.MemoryChannel" class Arnie def initialize(channel, consumer) @channel = channel @consumer = consumer end def start on_receive = Proc.new 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 @channel.subscribe(@consumer, on_receive) @consumer.start end def ^(message) @channel.publish(message) end end terminator = Arnie.new(MemoryChannel.new, ThreadFiber.new) terminator.start terminator ^ "Terminate" terminator ^ "Buy me icecream" terminator ^ "The End" terminator ^ "Terminate" # Will not execute as terminator is already dead...