Method: Clasp::LockManager#lock

Defined in:
lib/clasp/lock_manager.rb

#lock(identifier) ⇒ undefined

Obtains the lock for the given identifier

Parameters:

  • identifier (Object)

Returns:

  • (undefined)

Raises:

  • (LockAcquisitonError)

    If the lock could not be acquired, usually due to deadlock



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/clasp/lock_manager.rb', line 15

def lock(identifier)
  obtained = false
  until obtained
    lock = @locks.compute_if_absent(identifier) {
      DisposableLock.new(self, identifier)
    }
    obtained = lock.lock
    unless obtained
      @locks.delete_pair(identifier, lock)
    end
  end
end