* Collect all remaining elements of a bounded stream into an array. * Obviously this will succeed only for small streams that fit in memory. * Useful for testing. * * @returns A Promise for an array of stream elements, which will resolve * when the stream is exhausted.
()
| 171 | * when the stream is exhausted. |
| 172 | */ |
| 173 | async toArray(): Promise<T[]> { |
| 174 | const result: T[] = []; |
| 175 | let x = await this.next(); |
| 176 | while (!x.done) { |
| 177 | result.push(x.value); |
| 178 | x = await this.next(); |
| 179 | } |
| 180 | return result; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Collect all elements of this dataset into an array with prefetching 100 |