lib/zookeeper/locker.rb
def with_lock(&blk)
      create_lock_file!
      queue = Queue.new

      first_lock_blk = lambda do
        if have_first_lock?(true)
           queue << :locked
         end
      end

      @zk.watcher.register(root_lock_path, &first_lock_blk)
      first_lock_blk.call

      if queue.pop
        begin
          @locked = true
          return blk.call
        ensure
          unlock!
        end
      end

    end
# a blocking lock that waits until the lock is available for continuing
# @param [Block] the block you want to execute once your client has
#   received the lock
# @example
#   zk.locker("boooyah").with_lock do
#     #some logic
#   end
a blocking lock that waits until the lock is available for continuing
a blocking lock that waits until the lock is available for continuing
def with_lock(&blk)
      create_lock_file!
      queue = Queue.new
      first_lock_blk = lambda do
        if have_first_lock?(true)
           queue << :locked
         end
      end
      @zk.watcher.register(root_lock_path, &first_lock_blk)
      first_lock_blk.call
      if queue.pop
        begin
          @locked = true
          return blk.call
        ensure
          unlock!
        end
      end
    end
def with_lock ( & blk ) create_lock_file! queue = Queue . new first_lock_blk = lambda do if have_first_lock? ( true ) queue << :locked end end @zk . watcher . register ( root_lock_path , & first_lock_blk ) first_lock_blk . call if queue . pop begin @locked = true return blk . call ensure unlock! end end end
a blocking lock that waits until the lock is available for continuing
a blocking lock that waits until the lock is available for continuing
blk
the block you want to execute once your client has received the lock
the block you want to execute once your client has received the lock
example
zk.locker("boooyah").with_lock do #some logic end
zk . locker ( " boooyah " ) . with_lock do #some logic end