Sha256: 7aa521cbbccd42fcb2db85f6707b8144a005aa0ae13da4df92922022e8b66648

Contents?: true

Size: 601 Bytes

Versions: 141

Compression:

Stored size: 601 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
    FLAG = 'rack.multithread'.freeze

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

    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
  end
end

Version data entries

141 entries across 125 versions & 32 rubygems

Version Path
scout_realtime-0.5.4 lib/vendor/rack-1.5.2/lib/rack/lock.rb
scout_realtime-0.5.3 lib/vendor/rack-1.5.2/lib/rack/lock.rb
scout_realtime-0.5.2 lib/vendor/rack-1.5.2/lib/rack/lock.rb
scout_realtime-0.5.1 lib/vendor/rack-1.5.2/lib/rack/lock.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/rack-1.5.2/lib/rack/lock.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/rack-1.5.2/lib/rack/lock.rb
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/rack-1.5.2/lib/rack/lock.rb
torquebox-console-0.3.0 vendor/bundle/jruby/1.9/gems/rack-1.5.2/lib/rack/lock.rb
challah-1.0.0 vendor/bundle/gems/rack-1.5.2/lib/rack/lock.rb
torquebox-console-0.2.5 vendor/bundle/jruby/1.9/gems/rack-1.5.2/lib/rack/lock.rb
torquebox-console-0.2.5 vendor/bundle/ruby/1.8/gems/rack-1.5.2/lib/rack/lock.rb
vagrant-actionio-0.0.9 vendor/bundle/gems/rack-1.5.2/lib/rack/lock.rb
torquebox-console-0.2.4 vendor/bundle/jruby/1.9/gems/rack-1.5.2/lib/rack/lock.rb
torquebox-console-0.2.4 vendor/bundle/ruby/1.8/gems/rack-1.5.2/lib/rack/lock.rb
torquebox-console-0.2.3 vendor/bundle/jruby/1.9/gems/rack-1.5.2/lib/rack/lock.rb
rack-1.5.2 lib/rack/lock.rb
devise_sociable-0.1.0 vendor/bundle/gems/rack-1.5.1/lib/rack/lock.rb
rack-1.5.1 lib/rack/lock.rb
rack-1.5.0 lib/rack/lock.rb
rack-1.5.0.beta.2 lib/rack/lock.rb