class Rack::Lock - rack-1.6.4 Documentation

# class Rack::Lock

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

### Constants

FLAG

### Public Class Methods

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

    # File lib/rack/lock.rb, line 10
    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 14
    def call(env)
      old, env[FLAG] = env[FLAG], false
      @mutex.lock
      response = @app.call(env)
      body = BodyProxy.new(response[2]) { @mutex.unlock }
      response[2] = body
      response
    ensure
      @mutex.unlock unless body
      env[FLAG] = old
    end