Skip to content

Commit de24d59

Browse files
fix: calling break out of streams should be instantaneous
1 parent c7bdda2 commit de24d59

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

lib/openai/internal/transport/pooled_net_requester.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,19 @@ def execute(request)
153153
end
154154

155155
self.class.calibrate_socket_timeout(conn, deadline)
156-
conn.request(req) do |rsp|
157-
y << [req, rsp]
158-
break if finished
159-
160-
rsp.read_body do |bytes|
161-
y << bytes.force_encoding(Encoding::BINARY)
162-
break if finished
163-
164-
self.class.calibrate_socket_timeout(conn, deadline)
156+
::Kernel.catch(:jump) do
157+
conn.request(req) do |rsp|
158+
y << [req, rsp]
159+
::Kernel.throw(:jump) if finished
160+
161+
rsp.read_body do |bytes|
162+
y << bytes.force_encoding(Encoding::BINARY)
163+
::Kernel.throw(:jump) if finished
164+
165+
self.class.calibrate_socket_timeout(conn, deadline)
166+
end
167+
eof = true
165168
end
166-
eof = true
167169
end
168170
end
169171
ensure

0 commit comments

Comments
 (0)