From: James Edward Gray II Date: 2004-11-06T08:23:32+09:00 Subject: Re: Threaded Observer On Nov 5, 2004, at 5:18 PM, James Edward Gray II wrote: > Help Thread gurus! :D Figures, I got it as soon as I pushed "Send". The correction is below, for the curious. Sorry about the noise. James Edward Gray II > #!/usr/bin/env ruby > > require "observer" > require "singleton" > > class Clock > include Observable > include Singleton > > def start( seconds_delay ) > @thread = Thread.new(self, seconds_delay) do |notifier, delay| > loop do > puts "Notifying..." changed # I often forget this, for some reason. > notifier.notify_observers > sleep delay > end > end > end > > def stop > unless @thread.nil? > @thread.kill > @thread = nil > end > end > end > > if $0 == __FILE__ > class TimePrinter > def update > puts Time.now > end > end > > clock = Clock.instance > clock.add_observer TimePrinter.new > > puts "Starting clock..." > clock.start 3 > sleep 10 > clock.stop > puts "Clock stopped..." > sleep 10 > end > > __END__ > > Thanks. > > James Edward Gray II > > >