()
| 382 | // =========================================================================== |
| 383 | |
| 384 | async read() { |
| 385 | // If there's data in the buffer, return it immediately |
| 386 | if (this.#slots.length > 0) { |
| 387 | const result = this.#drain(); |
| 388 | this.#resolvePendingWrites(); |
| 389 | // After draining, check if writer was closing and buffer is now empty |
| 390 | if (this.#writerState === 'closing' && this.#slots.length === 0) { |
| 391 | this.endDrained(); |
| 392 | } |
| 393 | return { __proto__: null, done: false, value: result }; |
| 394 | } |
| 395 | |
| 396 | // Buffer empty and writer closing = drain complete |
| 397 | if (this.#writerState === 'closing') { |
| 398 | this.endDrained(); |
| 399 | return { __proto__: null, done: true, value: undefined }; |
| 400 | } |
| 401 | |
| 402 | if (this.#writerState === 'closed') { |
| 403 | return { __proto__: null, done: true, value: undefined }; |
| 404 | } |
| 405 | |
| 406 | if (this.#writerState === 'errored') { |
| 407 | throw this.#error; |
| 408 | } |
| 409 | |
| 410 | const { promise, resolve, reject } = PromiseWithResolvers(); |
| 411 | this.#pendingReads.push({ __proto__: null, resolve, reject }); |
| 412 | return promise; |
| 413 | } |
| 414 | |
| 415 | consumerReturn() { |
| 416 | if (this.#consumerState !== 'active') return; |
no test coverage detected