Sha256: afef897ac592bb829bd34fc3f0427b520f817508b2a8cdadc3b7cf992076d636

Contents?: true

Size: 400 Bytes

Versions: 6

Compression:

Stored size: 400 Bytes

Contents

# frozen_string_literal: true

module Sequel::Plugins::WithLock
  module InstanceMethods
    # Execute block with lock
    #
    # @yield
    def with_lock(savepoint: true)
      return yield if @__locked
      @__locked = true

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
umbrellio-sequel-plugins-0.5.1.27 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.5.1.26 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.5.1.25 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.5.1.18 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.5.1.17 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.5.1 lib/sequel/plugins/with_lock.rb