def acquire
      return unless @running

      @lock.acquire.callback {
        if !@locked
          @onlocked.call if @onlocked
          @locked = true
        end

        # Re-acquire lock near the end of the period
        @extend_timer = EM.add_timer(@timeout.to_f * 2 / 3) {
          acquire()
        }
      }.errback { |e|
        if @locked
          # We were previously locked
          @onunlocked.call if @onunlocked
          @locked = false
        end

        if e.kind_of?(EM::Hiredis::RedisError)
          err = e.redis_error
          EM::Hiredis.logger.warn "Unexpected error acquiring #{@lock} #{err}"
        end

        @retry_timer = EM.add_timer(@retry_timeout) {
          acquire() unless @locked
        }
      }
    end
def acquire
      return unless @running

      @lock.acquire.callback {
        if !@locked
          @onlocked.call if @onlocked
          @locked = true
        end

        
        @extend_timer = EM.add_timer(@timeout.to_f * 2 / 3) {
          acquire()
        }
      }.errback { |e|
        if @locked
          
          @onunlocked.call if @onunlocked
          @locked = false
        end

        if e.kind_of?(EM::Hiredis::RedisError)
          err = e.redis_error
          EM::Hiredis.logger.warn "Unexpected error acquiring 
        end

        @retry_timer = EM.add_timer(@retry_timeout) {
          acquire() unless @locked
        }
      }
    end
def acquire return unless @running @lock . acquire . callback { if ! @locked @onlocked . call if @onlocked @locked = true end # Re-acquire lock near the end of the period @extend_timer = EM . add_timer ( @timeout . to_f * 2 / 3 ) { acquire ( ) } } . errback { | e | if @locked # We were previously locked @onunlocked . call if @onunlocked @locked = false end if e . kind_of? ( EM :: Hiredis :: RedisError ) err = e . redis_error EM :: Hiredis . logger . warn "Unexpected error acquiring #{@lock} #{err}" end @retry_timer = EM . add_timer ( @retry_timeout ) { acquire ( ) unless @locked } } end
Acquire the lock (called automatically by initialize)
Acquire the lock ( called automatically by initialize )