Method: Etcd::Mod::Lock#lock

Defined in:
lib/etcd/mod/lock.rb

#lock(key, ttl, opts = {}) ⇒ Object

rubocop:disable RescueException



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/etcd/mod/lock.rb', line 44

def lock(key, ttl, opts = {})
  key = "/" + key unless key.start_with? '/'
  lock_index = acquire_lock(key, ttl, opts)
  begin
    yield key
  rescue Exception => e
    raise e
  ensure
    delete_lock(key, index: lock_index)
  end
end