Class: Dapp::Lock::Base
- Inherits:
-
Object
- Object
- Dapp::Lock::Base
- Defined in:
- lib/dapp/lock/base.rb
Overview
Base
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name) ⇒ Base
constructor
A new instance of Base.
- #lock(timeout: 60, on_wait: nil, readonly: false) ⇒ Object
- #synchronize(*args) ⇒ Object
- #unlock ⇒ Object
Constructor Details
#initialize(name) ⇒ Base
Returns a new instance of Base.
8 9 10 11 |
# File 'lib/dapp/lock/base.rb', line 8 def initialize(name) @name = name @active_locks = 0 end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/dapp/lock/base.rb', line 6 def name @name end |
Instance Method Details
#lock(timeout: 60, on_wait: nil, readonly: false) ⇒ Object
13 14 15 16 |
# File 'lib/dapp/lock/base.rb', line 13 def lock(timeout: 60, on_wait: nil, readonly: false) _do_lock(timeout, on_wait, readonly) unless @active_locks > 0 @active_locks += 1 end |
#synchronize(*args) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/dapp/lock/base.rb', line 23 def synchronize(*args) lock(*args) begin yield if block_given? ensure unlock end end |
#unlock ⇒ Object
18 19 20 21 |
# File 'lib/dapp/lock/base.rb', line 18 def unlock @active_locks -= 1 _do_unlock if @active_locks.zero? end |