def start_watchers
      # Watcher callbacks are invoked in a separate Ruby thread. Note that there
      # is a possible deadlock between invoking watcher callbacks and calling
      # close(): if we get a watcher event and a close at around the same time,
      # the close might fire first. Closing the Zk handle will block on
      # dispatching outstanding watchers, but it does so holding the @zk_mutex,
      # causing a deadlock. Hence, we just have the watcher callback spin on the
      # @zk_mutex, aborting if the handle is ever closed.
      @child_watcher = Zookeeper::Callbacks::WatcherCallback.new do
        while true
          break if @zk.closed?
          if @zk_mutex.try_lock
            get_and_watch unless @zk.closed?
            @zk_mutex.unlock
            break
          end
        end
      end

      @stat_watcher = Zookeeper::Callbacks::WatcherCallback.new do
        while true
          break if @zk.closed?
          if @zk_mutex.try_lock
            stat_and_watch unless @zk.closed?
            @zk_mutex.unlock
            break
          end
        end
      end

      stat_and_watch
    end
def start_watchers
      # Watcher callbacks are invoked in a separate Ruby thread. Note that there
      # is a possible deadlock between invoking watcher callbacks and calling
      # close(): if we get a watcher event and a close at around the same time,
      # the close might fire first. Closing the Zk handle will block on
      # dispatching outstanding watchers, but it does so holding the @zk_mutex,
      # causing a deadlock. Hence, we just have the watcher callback spin on the
      # @zk_mutex, aborting if the handle is ever closed.
      @child_watcher = Zookeeper::Callbacks::WatcherCallback.new do
        while true
          break if @zk.closed?
          if @zk_mutex.try_lock
            get_and_watch unless @zk.closed?
            @zk_mutex.unlock
            break
          end
        end
      end

      @stat_watcher = Zookeeper::Callbacks::WatcherCallback.new do
        while true
          break if @zk.closed?
          if @zk_mutex.try_lock
            stat_and_watch unless @zk.closed?
            @zk_mutex.unlock
            break
          end
        end
      end

      stat_and_watch
    end
Since the watcher callbacks might invoke EventMachine, we wait until after
 EM startup to start watching for Zk events.