Class: Rack::Lock
- Inherits:
-
Object
- Object
- Rack::Lock
- 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
- #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.
10 11 12 |
# File 'lib/rack/lock.rb', line 10 def initialize(app, mutex = Mutex.new) @app, @mutex = app, mutex end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rack/lock.rb', line 14 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 |