Skip to content

Instantly share code, notes, and snippets.

@kares
Last active August 29, 2015 14:04
Show Gist options
  • Save kares/b08842beb8c34ee6900a to your computer and use it in GitHub Desktop.
Save kares/b08842beb8c34ee6900a to your computer and use it in GitHub Desktop.
ActionController::Live::Response partial <code>process</code> that happens on every "live" request
error = nil
# This processes the action in a child thread. It lets us return the
# response code and headers back up the rack stack, and still process
# the body in parallel with sending data to the client
Thread.new {
begin
super(name)
rescue => e
if @_response.committed?
begin
complete = ActionView::Base.streaming_completion_on_exception
@_response.stream.write(complete) if request.format == :html
@_response.stream.call_on_error
ensure
@_response.stream.close
end
else
error = e
end
ensure
@_response.commit!
end
}
@_response.await_commit
raise error if error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment