class Dapp::Dimg::Lock::Base

Attributes

name[R]

Public Class Methods

new(name) click to toggle source
# File lib/dapp/dimg/lock/base.rb, line 7
def initialize(name)
  @name = name
  @active_locks = 0
end

Public Instance Methods

lock(timeout: 60, on_wait: nil, readonly: false) click to toggle source
# File lib/dapp/dimg/lock/base.rb, line 12
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) { || ... } click to toggle source
# File lib/dapp/dimg/lock/base.rb, line 22
def synchronize(*args)
  lock(*args)
  begin
    yield if block_given?
  ensure
    unlock
  end
end
unlock() click to toggle source
# File lib/dapp/dimg/lock/base.rb, line 17
def unlock
  @active_locks -= 1
  _do_unlock if @active_locks.zero?
end

Protected Instance Methods

_do_lock(_timeout, _on_wait, _readonly) click to toggle source
# File lib/dapp/dimg/lock/base.rb, line 33
def _do_lock(_timeout, _on_wait, _readonly)
  raise
end
_do_unlock() click to toggle source
# File lib/dapp/dimg/lock/base.rb, line 37
def _do_unlock
  raise
end
_waiting(timeout, on_wait, &blk) click to toggle source
# File lib/dapp/dimg/lock/base.rb, line 41
def _waiting(timeout, on_wait, &blk)
  if on_wait
    on_wait.call { ::Timeout.timeout(timeout, &blk) }
  else
    ::Timeout.timeout(timeout, &blk)
  end
end