Class: Rack::Lock

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

Constant Summary collapse

FLAG =
'rack.multithread'.freeze

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Lock.



5
6
7
# File 'lib/rambo/middleware/lock.rb', line 5

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

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
# File 'lib/rambo/middleware/lock.rb', line 9

def call(env)
  old, env[FLAG] = env[FLAG], false
  @lock.synchronize { @app.call(env) }
ensure
  env[FLAG] = old
end