Sha256: e6b122b4e86e607e3df0ddb72d94ac233b2a4773b06f7bfa6d4ca35a9f2082e6

Contents?: true

Size: 748 Bytes

Versions: 1

Compression:

Stored size: 748 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)
      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
        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
      @running = false
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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