File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Expand file tree Collapse file tree 1 file changed +20
-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,18 @@ 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+ text , is_done = get_next_text (string.sub (text , start or 1 ))
190+ if is_done then
191+ local res = text
192+ text = nil
193+ index = nil
194+ if schedule then
195+ async .util .scheduler ()
196+ end
197+ return res
198+ else
199+ return next_value ()
200+ end
186201 end
187202
188203 index = index + 1
You can’t perform that action at this time.
0 commit comments