mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
d3c9d808e3
These should allow external code to run blocks of user code to do "work", at a similar unit size to a web request, without needing to get intimate with ActionDipatch.
19 lines
408 B
Ruby
19 lines
408 B
Ruby
require 'rack/body_proxy'
|
|
|
|
module ActionDispatch
|
|
class Executor
|
|
def initialize(app, executor)
|
|
@app, @executor = app, executor
|
|
end
|
|
|
|
def call(env)
|
|
state = @executor.run!
|
|
begin
|
|
response = @app.call(env)
|
|
returned = response << ::Rack::BodyProxy.new(response.pop) { state.complete! }
|
|
ensure
|
|
state.complete! unless returned
|
|
end
|
|
end
|
|
end
|
|
end
|