Class: Rack::Lock

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

Defined Under Namespace

Classes: Proxy

Constant Summary collapse

FLAG =
'rack.multithread'.freeze

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Lock.



27
28
29
# File 'lib/rack/lock.rb', line 27

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

Instance Method Details

#call(env) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rack/lock.rb', line 31

def call(env)
  old, env[FLAG] = env[FLAG], false
  @mutex.lock
  response = @app.call(env)
  response[2] = Proxy.new(response[2], @mutex)
  response
rescue Exception
  @mutex.unlock
  raise
ensure
  env[FLAG] = old
end