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)
159159 index = nil
160160
161161 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+ else
166+ -- the file doesn't end in a newline. flush the line contents we had and finish.
167+ return previous .. " \n " , true
168+ end
164169 end
165170
166171 read = string.gsub (read or " " , " \r " , " " )
167- return (previous or " " ) .. read
172+ return (previous or " " ) .. read , false
168173 end
169174
170175 local next_value = nil
@@ -181,8 +186,19 @@ function LinesPipe:iter(schedule)
181186 index = string.find (text , " \n " , index , true )
182187
183188 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 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
186202 end
187203
188204 index = index + 1
You can’t perform that action at this time.
0 commit comments