Class: RedisLock::Semaphore

Inherits:
Strategy show all
Defined in:
lib/redis_lock/semaphore.rb

Instance Attribute Summary

Attributes inherited from Strategy

#args, #lock

Instance Method Summary collapse

Methods inherited from Strategy

#initialize

Constructor Details

This class inherits a constructor from RedisLock::Strategy

Instance Method Details

#after_performObject



14
15
16
# File 'lib/redis_lock/semaphore.rb', line 14

def after_perform
  lock.unlock!
end

#call(&block) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/redis_lock/semaphore.rb', line 4

def call(&block)
  ttl = args[:ttl] || lock.config.default_ttl
  set_opts = args[:set_opts] || {}
  while lock.locked?
    sleep (args[:wait] || 1)
  end
  lock.set(ttl, set_opts)
  _perform(&block)
end