Class: Dapp::Lock::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/dapp/lock/base.rb

Overview

Base

Direct Known Subclasses

File

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (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

#unlockObject



18
19
20
21
# File 'lib/dapp/lock/base.rb', line 18

def unlock
  @active_locks -= 1
  _do_unlock if @active_locks.zero?
end