From e56cdf601f3df911321f74584054467387fba5ef Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Tue, 16 Dec 2008 14:32:50 -0800 Subject: [PATCH] Add async.close deferrable which is triggered when the http connection is closed --- lib/thin/connection.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/thin/connection.rb b/lib/thin/connection.rb index 5bafbee0..ef87ce0b 100644 --- a/lib/thin/connection.rb +++ b/lib/thin/connection.rb @@ -69,6 +69,7 @@ def pre_process # It should be noted that connection objects will linger until this # callback is no longer referenced, so be tidy! @request.env['async.callback'] = method(:post_process) + @request.env['async.close'] = EM::DefaultDeferrable.new # When we're under a non-async framework like rails, we can still spawn # off async responses using the callback info, so there's little point @@ -129,6 +130,7 @@ def handle_error end def close_request_response + @request.env['async.close'].succeed @request.close rescue nil @response.close rescue nil end @@ -152,6 +154,7 @@ def terminate_request # Called when the connection is unbinded from the socket # and can no longer be used to process requests. def unbind + @request.env['async.close'].succeed if @request.env['async.close'] @response.body.fail if @response.body.respond_to?(:fail) @backend.connection_finished(self) end