123456789_123456789_123456789_123456789_123456789_

Class: Rack::Lock

Relationships & Source Files
Inherits: Object
Defined in: lib/rack/lock.rb

Overview

Lock locks every request inside a mutex, so that every request will effectively be executed synchronously.

Class Method Summary

Instance Method Summary

Constructor Details

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

[ GitHub ]

  
# File 'lib/rack/lock.rb', line 9

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

Instance Method Details

#call(env)

[ GitHub ]

  
# File 'lib/rack/lock.rb', line 13

def call(env)
  @mutex.lock
  begin
    response = @app.call(env)
    returned = response << BodyProxy.new(response.pop) { unlock }
  ensure
    unlock unless returned
  end
end

#unlock (private)

[ GitHub ]

  
# File 'lib/rack/lock.rb', line 25

def unlock
  @mutex.unlock
end