Sha256: e8b5255846b736922c48bdf1c406a740a580e00c20f5bf09cec98d91b8877c4d
Contents?: true
Size: 711 Bytes
Versions: 39
Compression:
Stored size: 711 Bytes
Contents
require 'thread' require 'rack/body_proxy' module Rack # Rack::Lock locks every request inside a mutex, so that every request # will effectively be executed synchronously. class Lock def initialize(app, mutex = Mutex.new) @app, @mutex = app, mutex end 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 private def unlock @mutex.unlock @env[RACK_MULTITHREAD] = @old_rack_multithread end end end
Version data entries
39 entries across 37 versions & 9 rubygems