Class: Rack::Lock
- Inherits:
-
Object
- Object
- Rack::Lock
- Defined in:
- lib/rack/lock.rb
Constant Summary collapse
- FLAG =
'rack.multithread'.freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, mutex = Mutex.new) ⇒ Lock
constructor
A new instance of Lock.
Constructor Details
#initialize(app, mutex = Mutex.new) ⇒ Lock
Returns a new instance of 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 21 22 23 |
# File 'lib/rack/lock.rb', line 12 def call(env) old, env[FLAG] = env[FLAG], false @mutex.lock response = @app.call(env) response[2] = BodyProxy.new(response[2]) { @mutex.unlock } response rescue Exception @mutex.unlock raise ensure env[FLAG] = old end |