Sha256: 3584964fbf6539f657c1b13248840455a8626f4b9f764e470d8779b5d4bb7bd0

Contents?: true

Size: 716 Bytes

Versions: 64

Compression:

Stored size: 716 Bytes

Contents

# frozen_string_literal: true

require 'thread'

module Rack
  # Rack::Lock locks every request inside a mutex, so that every request
  # will effectively be executed synchronously.
  class Lock
    def initialize(app, mutex = Mutex.new)
      @app, @mutex = app, mutex
    end

    def call(env)
      @mutex.lock
      @env = env
      @old_rack_multithread = env[RACK_MULTITHREAD]
      begin
        response = @app.call(env.merge!(RACK_MULTITHREAD => false))
        returned = response << BodyProxy.new(response.pop) { unlock }
      ensure
        unlock unless returned
      end
    end

    private

    def unlock
      @mutex.unlock
      @env[RACK_MULTITHREAD] = @old_rack_multithread
    end
  end
end

Version data entries

64 entries across 48 versions & 15 rubygems

Version Path
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/lock.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/lock.rb
rack-2.2.6.2 lib/rack/lock.rb
rack-2.2.6.1 lib/rack/lock.rb
rack-2.2.6 lib/rack/lock.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/lock.rb
rack-2.2.5 lib/rack/lock.rb
diy_rails-0.1.0 vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/lock.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/rack-2.2.4/lib/rack/lock.rb
rack-2.2.4 lib/rack/lock.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/rack-2.2.3.1/lib/rack/lock.rb
rack-2.2.3.1 lib/rack/lock.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/2.6.0/gems/rack-2.2.3/lib/rack/lock.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/3.0.0/gems/rack-2.2.3/lib/rack/lock.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/3.1.0/gems/rack-2.2.3/lib/rack/lock.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/rack-2.2.3/lib/rack/lock.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/lock.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/rack-2.2.3/lib/rack/lock.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/rack-2.2.3/lib/rack/lock.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/rack-2.2.3/lib/rack/lock.rb