Sha256: ad78f3b06a07c1b1edfa2bef5439bf0c05789c724c6ab646a3044848e51a8f63

Contents?: true

Size: 434 Bytes

Versions: 32

Compression:

Stored size: 434 Bytes

Contents

# frozen_string_literal: true

module Sequel::Plugins::WithLock
  module InstanceMethods
    # Execute block with lock
    #
    # @yield
    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
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
umbrellio-sequel-plugins-0.12.0.159 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.11.0.143 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.10.0.101 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.10.0.100 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.10.0.86 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.9.0.79 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.9.0.76 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.8.0.73 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.7.0.52 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.6.0.46 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.6.0 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.6.0.36 lib/sequel/plugins/with_lock.rb