* Iterator next function. * @returns the next line, or undefined if the iterator is done.
()
| 180 | */ |
| 181 | |
| 182 | async next(): Promise<IteratorResult<string>> { |
| 183 | do { |
| 184 | // is the current line (regardless of whether it's full or not) a match |
| 185 | const value = this.lineBuffer.at(this.current); |
| 186 | if (value !== undefined && this.isMatch(value)) { |
| 187 | // we have a match, so we're done |
| 188 | return { value: undefined, done: true }; |
| 189 | } |
| 190 | |
| 191 | // if we have lines to take, take them |
| 192 | if (this.current < this.lineBuffer.last) { |
| 193 | this.advance(); |
| 194 | return { value, done: false }; |
| 195 | } |
| 196 | // otherwise, we're at the end. if the process is done, then so are we. |
| 197 | if (this.lineBuffer.completed) { |
| 198 | return { value: undefined, done: true }; |
| 199 | } |
| 200 | |
| 201 | // we need to wait for more lines to show up |
| 202 | await this.lineBuffer.changed; |
| 203 | } while (true); |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * returns the number of lines available to read. |