diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-07-27 15:54:11 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-07-27 15:54:23 -0700 |
commit | acb6848468bc4ec035201b23af9affeb8279711f (patch) | |
tree | 601a3d3e6136d8c06a06c977f2fc839a563600ce /actionpack/lib/action_dispatch/http | |
parent | f4d818d51e64a025f78fca15fdae2391ed072656 (diff) | |
download | rails-acb6848468bc4ec035201b23af9affeb8279711f.tar.gz rails-acb6848468bc4ec035201b23af9affeb8279711f.tar.bz2 rails-acb6848468bc4ec035201b23af9affeb8279711f.zip |
threads can wait on responses to be committed
Diffstat (limited to 'actionpack/lib/action_dispatch/http')
-rw-r--r-- | actionpack/lib/action_dispatch/http/response.rb | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index cc46f9983c..d590a23a81 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -2,6 +2,7 @@ require 'digest/md5' require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/object/blank' require 'active_support/core_ext/class/attribute_accessors' +require 'monitor' module ActionDispatch # :nodoc: # Represents an HTTP response generated by a controller action. Use it to @@ -62,12 +63,17 @@ module ActionDispatch # :nodoc: include Rack::Response::Helpers include ActionDispatch::Http::Cache::Response + include MonitorMixin def initialize(status = 200, header = {}, body = []) + super() + self.body, self.header, self.status = body, header, status @sending_file = false - @blank = false + @blank = false + @cv = new_cond + @committed = false if content_type = self[CONTENT_TYPE] type, charset = content_type.split(/;\s*charset=/) @@ -80,6 +86,23 @@ module ActionDispatch # :nodoc: yield self if block_given? end + def await_commit + synchronize do + @cv.wait_until { @committed } + end + end + + def commit! + synchronize do + @committed = true + @cv.broadcast + end + end + + def committed? + synchronize { @committed } + end + def status=(status) @status = Rack::Utils.status_code(status) end |