lib/syncrony/observer.rb in syncrony-0.0.1 vs lib/syncrony/observer.rb in syncrony-1.0.0

- old
+ new

@@ -11,21 +11,26 @@ @path = path @running = true end def run(&handler) - info = @client.info(@path) - value = info ? info[:value] : nil - index = info ? info[:index] : nil + begin + info = @client.get(@path) + value = info.value + index = info.etcd_index + rescue Etcd::KeyNotFound + info = nil + value = nil + index = nil + end yield value, @path, info while @running - @client.watch(@path, :index => index ? index + 1 : nil) do |w_value, w_key, w_info| - if @running - index = w_info[:index] - yield w_value, w_key, w_info - end + watch = @client.watch(@path, :index => index ? index + 1 : nil) + if @running + index = watch.etcd_index + yield watch.value, @path, watch end end end def cancel