Class: RedisLock::Semaphore
- Inherits:
-
Object
- Object
- RedisLock::Semaphore
- Defined in:
- lib/redis_lock/semaphore.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#lock ⇒ Object
readonly
Returns the value of attribute lock.
Instance Method Summary collapse
- #call(&block) ⇒ Object
-
#initialize(lock, args = {}) ⇒ Semaphore
constructor
A new instance of Semaphore.
Constructor Details
#initialize(lock, args = {}) ⇒ Semaphore
Returns a new instance of Semaphore.
5 6 7 8 |
# File 'lib/redis_lock/semaphore.rb', line 5 def initialize(lock, args = {}) @lock = lock @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
3 4 5 |
# File 'lib/redis_lock/semaphore.rb', line 3 def args @args end |
#lock ⇒ Object (readonly)
Returns the value of attribute lock.
3 4 5 |
# File 'lib/redis_lock/semaphore.rb', line 3 def lock @lock end |
Instance Method Details
#call(&block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/redis_lock/semaphore.rb', line 10 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) out = _perform(&block) lock.unlock! out end |