* Splits the stream into two streams which can be * independently read from at different speeds.
()
| 155 | * independently read from at different speeds. |
| 156 | */ |
| 157 | tee(): [Stream<Item>, Stream<Item>] { |
| 158 | const left: Array<Promise<IteratorResult<Item>>> = []; |
| 159 | const right: Array<Promise<IteratorResult<Item>>> = []; |
| 160 | const iterator = this.iterator(); |
| 161 | |
| 162 | const teeIterator = ( |
| 163 | queue: Array<Promise<IteratorResult<Item>>> |
| 164 | ): AsyncIterator<Item> => { |
| 165 | return { |
| 166 | next: () => { |
| 167 | if (queue.length === 0) { |
| 168 | const result = iterator.next(); |
| 169 | left.push(result); |
| 170 | right.push(result); |
| 171 | } |
| 172 | return queue.shift()!; |
| 173 | } |
| 174 | }; |
| 175 | }; |
| 176 | |
| 177 | return [ |
| 178 | new Stream(() => teeIterator(left), this.controller), |
| 179 | new Stream(() => teeIterator(right), this.controller) |
| 180 | ]; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Converts this stream to a newline-separated ReadableStream of |
no test coverage detected