mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-18 00:00:56 -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
|
end
|
||||||
# parser.inherit_callbacks(self)
|
# parser.inherit_callbacks(self)
|
||||||
parser.on(:complete) { throw(:close, self) }
|
parser.on(:complete) { throw(:close, self) }
|
||||||
|
parser.on(:close) do
|
||||||
|
transition(:closed)
|
||||||
|
emit(:close)
|
||||||
|
end
|
||||||
parser
|
parser
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -22,11 +22,16 @@ module HTTPX
|
|||||||
@has_response = false
|
@has_response = false
|
||||||
end
|
end
|
||||||
|
|
||||||
def close
|
def reset
|
||||||
@parser.reset!
|
@parser.reset!
|
||||||
@has_response = false
|
@has_response = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def close
|
||||||
|
reset
|
||||||
|
emit(:close)
|
||||||
|
end
|
||||||
|
|
||||||
def empty?
|
def empty?
|
||||||
# this means that for every request there's an available
|
# this means that for every request there's an available
|
||||||
# partial response, so there are no in-flight requests waiting.
|
# partial response, so there are no in-flight requests waiting.
|
||||||
|
@ -27,15 +27,10 @@ module HTTPX
|
|||||||
|
|
||||||
def close(channel = nil)
|
def close(channel = nil)
|
||||||
if channel
|
if channel
|
||||||
if channel.close
|
channel.close
|
||||||
@channels.delete(channel)
|
|
||||||
@selector.deregister(channel)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
while (ch = @channels.shift)
|
@channels.each(&:close)
|
||||||
ch.close(true)
|
next_tick until @selector.empty?
|
||||||
@selector.deregister(ch)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -60,6 +55,10 @@ module HTTPX
|
|||||||
def register_channel(channel)
|
def register_channel(channel)
|
||||||
monitor = @selector.register(channel, :w)
|
monitor = @selector.register(channel, :w)
|
||||||
monitor.value = channel
|
monitor.value = channel
|
||||||
|
channel.on(:close) do
|
||||||
|
@channels.delete(channel)
|
||||||
|
@selector.deregister(channel)
|
||||||
|
end
|
||||||
@channels << channel
|
@channels << channel
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -48,6 +48,10 @@ class HTTPX::Selector
|
|||||||
@closed = false
|
@closed = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def empty?
|
||||||
|
@readers.empty? && @writers.empty?
|
||||||
|
end
|
||||||
|
|
||||||
# deregisters +io+ from selectables.
|
# deregisters +io+ from selectables.
|
||||||
def deregister(io)
|
def deregister(io)
|
||||||
@lock.synchronize do
|
@lock.synchronize do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user