File tree Expand file tree Collapse file tree 1 file changed +21
-5
lines changed Expand file tree Collapse file tree 1 file changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -159,12 +159,17 @@ function LinesPipe:iter(schedule)
159
159
index = nil
160
160
161
161
local read = self :read ()
162
- if previous == nil and read == nil then
163
- return
162
+ if read == nil then
163
+ if previous == nil then
164
+ return nil , true
165
+ elseif # previous > 0 then
166
+ -- the file doesn't end in a newline. flush the line contents we had and finish.
167
+ return previous .. " \n " , true
168
+ end
164
169
end
165
170
166
171
read = string.gsub (read or " " , " \r " , " " )
167
- return (previous or " " ) .. read
172
+ return (previous or " " ) .. read , false
168
173
end
169
174
170
175
local next_value = nil
@@ -181,8 +186,19 @@ function LinesPipe:iter(schedule)
181
186
index = string.find (text , " \n " , index , true )
182
187
183
188
if index == nil then
184
- text = get_next_text (string.sub (text , start or 1 ))
185
- return next_value ()
189
+ local is_done
190
+ text , is_done = get_next_text (string.sub (text , start or 1 ))
191
+ if is_done and text ~= nil then
192
+ local res = text
193
+ text = nil
194
+ index = nil
195
+ if schedule then
196
+ async .util .scheduler ()
197
+ end
198
+ return res
199
+ else
200
+ return next_value ()
201
+ end
186
202
end
187
203
188
204
index = index + 1
You can’t perform that action at this time.
0 commit comments