aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/middleware/load_interlock.rb
blob: 07f498319c106831b6e9d3aacd52779bf9e4ba99 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'active_support/dependencies'
require 'rack/body_proxy'

module ActionDispatch
  class LoadInterlock
    def initialize(app)
      @app = app
    end

    def call(env)
      interlock = ActiveSupport::Dependencies.interlock
      interlock.start_running
      response = @app.call(env)
      body = Rack::BodyProxy.new(response[2]) { interlock.done_running }
      response[2] = body
      response
    ensure
      interlock.done_running unless body
    end
  end
end