channels are resettable (meaning, they transition to closed right away), which is important for when there is an error (like timeout or network)

This commit is contained in:
HoneyryderChuck 2018-02-24 00:11:10 +00:00
parent 8e8240f5fc
commit ab69d4aa39
3 changed files with 12 additions and 1 deletions

View File

@ -112,6 +112,12 @@ module HTTPX
end
end
def reset
transition(:closing)
transition(:closed)
emit(:close)
end
def send(request, **args)
if @parser && !@write_buffer.full?
parser.send(request, **args)
@ -139,7 +145,7 @@ module HTTPX
end
def upgrade_parser(protocol)
@parser.close if @parser
@parser.reset if @parser
@parser = build_parser(protocol)
end

View File

@ -108,6 +108,7 @@ module HTTPX
break if requests.empty?
rescue TimeoutError => e
responses << ErrorResponse.new(e.message, 0) while requests.shift
@connection.reset
break
end
end

View File

@ -34,6 +34,10 @@ module HTTPX
end
end
def reset
@channels.each(&:reset)
end
def build_channel(uri, **options)
channel = Channel.by(uri, @options.merge(options))
register_channel(channel)