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