# class Rack::Lock

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

### Public Class Methods

new(app, mutex = Mutex.new) click to toggle source

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

### Public Instance Methods

call(env) click to toggle source

    # 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

### Private Instance Methods

unlock() click to toggle source

    # File lib/rack/lock.rb, line 27
    def unlock
      @mutex.unlock
      @env[RACK_MULTITHREAD] = @old_rack_multithread
    end