Skip to content

Commit 73cd595

Browse files
add: eof var
1 parent 917ca89 commit 73cd595

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/ld-eventsource/client.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def initialize(uri,
119119
@uri = URI(uri)
120120
@stopped = Concurrent::AtomicBoolean.new(false)
121121
@retry_enabled = retry_enabled
122+
@eof = false
122123

123124
@headers = headers.clone
124125
@connect_timeout = connect_timeout
@@ -265,6 +266,7 @@ def run_stream
265266
# connected but before @cxn was set. Checking the variable again is a bit clunky but avoids that.
266267
return if @stopped.value
267268
read_stream(resp) unless resp.nil?
269+
return close if @eof
268270
rescue => e
269271
# When we deliberately close the connection, it will usually trigger an exception. The exact type
270272
# of exception depends on the specific Ruby runtime. But @stopped will always be set in this case.
@@ -344,7 +346,12 @@ def read_stream(cxn)
344346
# For historical reasons, we rethrow this as our own type
345347
raise Errors::ReadTimeoutError.new(@read_timeout)
346348
end
347-
break if data.nil?
349+
350+
if data.nil?
351+
@eof = true
352+
break
353+
end
354+
348355
gen.yield data
349356
end
350357
end

0 commit comments

Comments
 (0)