Class: Syncrony::Observer
- Inherits:
-
Object
- Object
- Syncrony::Observer
- Defined in:
- lib/syncrony/observer.rb
Instance Attribute Summary collapse
-
#running ⇒ Object
Returns the value of attribute running.
Instance Method Summary collapse
- #cancel ⇒ Object
-
#initialize(client, path) ⇒ Observer
constructor
A new instance of Observer.
- #run {|value, @path, info| ... } ⇒ Object
Constructor Details
#initialize(client, path) ⇒ Observer
Returns a new instance of Observer.
9 10 11 12 13 |
# File 'lib/syncrony/observer.rb', line 9 def initialize(client, path) @client = client @path = path @running = true end |
Instance Attribute Details
#running ⇒ Object
Returns the value of attribute running.
7 8 9 |
# File 'lib/syncrony/observer.rb', line 7 def running @running end |
Instance Method Details
#cancel ⇒ Object
37 38 39 |
# File 'lib/syncrony/observer.rb', line 37 def cancel @running = false end |
#run {|value, @path, info| ... } ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/syncrony/observer.rb', line 15 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 |