Class: Rack::Lock

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/lock.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(app, mutex = Mutex.new) ⇒ Lock



8
9
10
# File 'lib/rack/lock.rb', line 8

def initialize(app, mutex = Mutex.new)
  @app, @mutex = app, mutex
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/rack/lock.rb', line 12

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