()
| 431 | } |
| 432 | |
| 433 | #createRawConsumer() { |
| 434 | const state = { |
| 435 | __proto__: null, |
| 436 | cursor: this.#bufferStart, |
| 437 | detached: false, |
| 438 | }; |
| 439 | |
| 440 | this.#consumers.add(state); |
| 441 | if (this.#consumers.size === 1) { |
| 442 | this.#cachedMinCursor = state.cursor; |
| 443 | this.#cachedMinCursorConsumers = 1; |
| 444 | } else if (state.cursor === this.#cachedMinCursor) { |
| 445 | this.#cachedMinCursorConsumers++; |
| 446 | } else { |
| 447 | this.#recomputeMinCursor(); |
| 448 | } |
| 449 | const self = this; |
| 450 | |
| 451 | return { |
| 452 | __proto__: null, |
| 453 | [SymbolIterator]() { |
| 454 | return { |
| 455 | __proto__: null, |
| 456 | next() { |
| 457 | if (state.detached) { |
| 458 | return { __proto__: null, done: true, value: undefined }; |
| 459 | } |
| 460 | if (self.#sourceError) { |
| 461 | state.detached = true; |
| 462 | self.#deleteConsumer(state); |
| 463 | throw self.#sourceError; |
| 464 | } |
| 465 | if (self.#cancelled) { |
| 466 | state.detached = true; |
| 467 | self.#deleteConsumer(state); |
| 468 | return { __proto__: null, done: true, value: undefined }; |
| 469 | } |
| 470 | |
| 471 | const bufferIndex = state.cursor - self.#bufferStart; |
| 472 | if (bufferIndex < self.#buffer.length) { |
| 473 | const chunk = self.#buffer.get(bufferIndex); |
| 474 | const cursor = state.cursor; |
| 475 | state.cursor++; |
| 476 | if (cursor === self.#cachedMinCursor && |
| 477 | --self.#cachedMinCursorConsumers === 0) { |
| 478 | self.#tryTrimBuffer(); |
| 479 | } |
| 480 | return { __proto__: null, done: false, value: chunk }; |
| 481 | } |
| 482 | |
| 483 | if (self.#sourceExhausted) { |
| 484 | state.detached = true; |
| 485 | self.#deleteConsumer(state); |
| 486 | return { __proto__: null, done: true, value: undefined }; |
| 487 | } |
| 488 | |
| 489 | // Check buffer limit |
| 490 | if (self.#buffer.length >= self.#options.highWaterMark) { |
no test coverage detected