I'm trying to get a sample to work with Ruby 1.8.6. The problem is that the sample was written for Ruby 1.8.5.
My assumption is that the problem lies in the way the Thread is called, or not called. This is the sample:
class Timer
def initialize(resolution)
@resolution = resolution
@queue = []
Thread.new do
while true
dispatch
sleep(@resolution)
end
end
end
def at(time, &block)
time = time.to_f if time.kind_of?(Time)
@queue.push [time, block]
end
private
def dispatch
now = Time.now.to_f
ready, @queue = @queue.partition{|time, proc| time <= now }
ready.each {|time, proc| proc.call(time) }
end
end
timer = Timer.new(0.01)
timer.at(Time.now + 3) { puts "Hello" }
I can't get it to work with 1.8.6 so I hope someone can show me how to make it compatible with 1.8.6
Thanks