mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-10 00:01:27 -04:00
calling close on parse triggers the channel close; this will eventually trigger its callback (close is not immediate)
This commit is contained in:
parent
1f6862f3f2
commit
1cbec1b959
@ -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
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user