Sha256: 3b42bb7dbd052575842748bb222ebdb19f226744bc3b1a91727d6db5ce053f2c

Contents?: true

Size: 691 Bytes

Versions: 1

Compression:

Stored size: 691 Bytes

Contents

require 'celluloid'
require 'etcd'

module Syncrony
  class Observer

    attr_accessor :running

    def initialize(client, path)
      @client = client
      @path = path
      @running = true
    end

    def run(&handler)
      info = @client.info(@path)
      value = info ? info[:value] : nil
      index = info ? info[:index] : nil

      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
        end
      end
    end

    def cancel
      @running = false
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
syncrony-0.0.1 lib/syncrony/observer.rb