calling close on parse triggers the channel close; this will eventually trigger its callback (close is not immediate)

This commit is contained in:
HoneyryderChuck 2018-02-24 00:06:01 +00:00
parent 1f6862f3f2
commit 1cbec1b959
4 changed files with 21 additions and 9 deletions

View File

@ -180,6 +180,10 @@ module HTTPX
end
# parser.inherit_callbacks(self)
parser.on(:complete) { throw(:close, self) }
parser.on(:close) do
transition(:closed)
emit(:close)
end
parser
end

View File

@ -22,11 +22,16 @@ module HTTPX
@has_response = false
end
def close
def reset
@parser.reset!
@has_response = false
end
def close
reset
emit(:close)
end
def empty?
# this means that for every request there's an available
# partial response, so there are no in-flight requests waiting.

View File

@ -27,15 +27,10 @@ module HTTPX
def close(channel = nil)
if channel
if channel.close
@channels.delete(channel)
@selector.deregister(channel)
end
channel.close
else
while (ch = @channels.shift)
ch.close(true)
@selector.deregister(ch)
end
@channels.each(&:close)
next_tick until @selector.empty?
end
end
@ -60,6 +55,10 @@ module HTTPX
def register_channel(channel)
monitor = @selector.register(channel, :w)
monitor.value = channel
channel.on(:close) do
@channels.delete(channel)
@selector.deregister(channel)
end
@channels << channel
end

View File

@ -48,6 +48,10 @@ class HTTPX::Selector
@closed = false
end
def empty?
@readers.empty? && @writers.empty?
end
# deregisters +io+ from selectables.
def deregister(io)
@lock.synchronize do