Skip to content

Commit

Permalink
Add async.close deferrable which is triggered when the http connectio…
Browse files Browse the repository at this point in the history
…n is closed
  • Loading branch information
tmm1 committed Dec 16, 2008
1 parent 20a46fb commit e56cdf6
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/thin/connection.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e56cdf6

Please sign in to comment.