Sha256: f04718fe92c5b76c733140307891f3fbe394f89d691fb73ff51acc31476d88ef

Contents?: true

Size: 361 Bytes

Versions: 20

Compression:

Stored size: 361 Bytes

Contents

# frozen_string_literal: true

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

      begin
        db.transaction do
          lock!
          yield
        end
      ensure
        @__locked = false
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
umbrellio-sequel-plugins-0.5.0 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.4.0.164 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.4.0.152 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.4.0.145 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.4.0.134 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.4.0.121 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.4.0.114 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.4.0.112 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.4.0.107 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.4.0.81 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.3.1.77 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.3.1.69 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.3.1.68 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.3.0.67 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.3.0.62 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.3.0 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.2.0 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.1.2 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.1.1 lib/sequel/plugins/with_lock.rb
umbrellio-sequel-plugins-0.1.0 lib/sequel/plugins/with_lock.rb