class Rack::Lock

Rack::Lock locks every request inside a mutex, so that every request will effectively be executed synchronously.

Public Class Methods

# File lib/rack/lock.rb, line 9
def initialize(app, mutex = Mutex.new)
  @app, @mutex = app, mutex
end

Public Instance Methods

# File lib/rack/lock.rb, line 13
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