Class: Rack::Lock
- Inherits:
-
Object
- Object
- Rack::Lock
- Defined in:
- rack/rack/lock.rb
Overview
Rack::Lock locks every request inside a mutex, so that every request will effectively be executed synchronously.
Constant Summary
- FLAG =
'rack.multithread'.freeze
Instance Method Summary (collapse)
- - (void) call(env)
-
- (Lock) initialize(app, mutex = Mutex.new)
constructor
A new instance of Lock.
Constructor Details
- (Lock) initialize(app, mutex = Mutex.new)
Returns a new instance of Lock
10 11 12 |
# File 'rack/rack/lock.rb', line 10 def initialize(app, mutex = Mutex.new) @app, @mutex = app, mutex end |
Instance Method Details
- (void) call(env)
14 15 16 17 18 19 20 21 22 23 24 |
# File 'rack/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 |