Module: Sequel::Plugins::WithLock::InstanceMethods

Defined in:
lib/sequel/plugins/with_lock.rb

Instance Method Summary collapse

Instance Method Details

#with_lock(mode = "FOR NO KEY UPDATE", savepoint: true) { ... } ⇒ Object

Execute block with lock

Yields:



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/sequel/plugins/with_lock.rb', line 8

def with_lock(mode = "FOR NO KEY UPDATE", savepoint: true)
  return yield if @__locked
  @__locked = true

  begin
    db.transaction(savepoint: savepoint) do
      lock!(mode)
      yield
    end
  ensure
    @__locked = false
  end
end