Sha256: 2e7310a3af22290dddae4b858837497cdd2121ebf71787d7500caa4edf4f9ffc
Contents?: true
Size: 797 Bytes
Versions: 30
Compression:
Stored size: 797 Bytes
Contents
# docs/examples/events_02.rb require 'thread' require 'zk' class Events def initialize @zk = ZK.new @queue = Queue.new @path = '/zk-example-events01' end def do_something_with(data) puts "I was told to say #{data.inspect}" @queue.push(:got_event) end def run @zk.register(@path) do |event| if event.node_changed? or event.node_created? data = @zk.get(@path, watch: true).first # fetch the latest data and re-set watch do_something_with(data) end end begin @zk.delete(@path) rescue ZK::Exceptions::NoNode end @zk.stat(@path, watch: true) @zk.create(@path, 'Hello, events!') @queue.pop @zk.set(@path, "ooh, an update!") @queue.pop ensure @zk.close! end end Events.new.run
Version data entries
30 entries across 30 versions & 1 rubygems