| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 45780df commit 74bd0cd
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -426,6 +426,7 @@ class PushQueue { | |||
| 426 | 426 | if (this.#consumerState !== 'active') return; | |
| 427 | 427 | this.#consumerState = 'returned'; | |
| 428 | 428 | this.#cleanup(); | |
| 429 | + this.#resolvePendingReads(); | ||
| 429 | 430 | this.#rejectPendingWrites( | |
| 430 | 431 | new ERR_INVALID_STATE.TypeError('Stream closed by consumer')); | |
| 431 | 432 | // If closing, reject the pending end promise | |
@@ -443,7 +444,12 @@ class PushQueue { | |||
| 443 | 444 | this.#consumerState = 'thrown'; | |
| 444 | 445 | this.#error = error; | |
| 445 | 446 | this.#cleanup(); | |
| 447 | + this.#rejectPendingReads(error); | ||
| 446 | 448 | this.#rejectPendingWrites(error); | |
| 449 | + if (this.#writerState === 'closing' && this.#pendingEnd) { | ||
| 450 | + this.#pendingEnd.reject(error); | ||
| 451 | + this.#pendingEnd = null; | ||
| 452 | + } | ||
| 447 | 453 | // Reject pending drains - the consumer errored | |
| 448 | 454 | this.#rejectPendingDrains(error); | |
| 449 | 455 | } | |
@@ -485,6 +491,9 @@ class PushQueue { | |||
| 485 | 491 | } else if (this.#writerState === 'errored' && this.#error) { | |
| 486 | 492 | const pending = this.#pendingReads.shift(); | |
| 487 | 493 | pending.reject(this.#error); | |
| 494 | + } else if (this.#consumerState === 'returned') { | ||
| 495 | + const pending = this.#pendingReads.shift(); | ||
| 496 | + pending.resolve({ __proto__: null, value: undefined, done: true }); | ||
| 488 | 497 | } else { | |
| 489 | 498 | break; | |
| 490 | 499 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -326,6 +326,44 @@ async function testFailRejectsPendingRead() { | |||
| 326 | 326 | ); | |
| 327 | 327 | } | |
| 328 | 328 | ||
| 329 | + // iterator.return() resolves a pending read with done:true | ||
| 330 | + async function testConsumerReturnResolvesPendingRead() { | ||
| 331 | + const { readable } = push(); | ||
| 332 | + | ||
| 333 | + const iter = readable[Symbol.asyncIterator](); | ||
| 334 | + const readPromise = iter.next(); | ||
| 335 | + | ||
| 336 | + await new Promise(setImmediate); | ||
| 337 | + | ||
| 338 | + const returnResult = await iter.return(); | ||
| 339 | + assert.strictEqual(returnResult.value, undefined); | ||
| 340 | + assert.strictEqual(returnResult.done, true); | ||
| 341 | + | ||
| 342 | + const readResult = await readPromise; | ||
| 343 | + assert.strictEqual(readResult.value, undefined); | ||
| 344 | + assert.strictEqual(readResult.done, true); | ||
| 345 | + } | ||
| 346 | + | ||
| 347 | + // iterator.throw() rejects a pending read with the thrown error | ||
| 348 | + async function testConsumerThrowRejectsPendingRead() { | ||
| 349 | + const { readable } = push(); | ||
| 350 | + | ||
| 351 | + const iter = readable[Symbol.asyncIterator](); | ||
| 352 | + const readPromise = iter.next(); | ||
| 353 | + | ||
| 354 | + await new Promise(setImmediate); | ||
| 355 | + | ||
| 356 | + const err = new Error('consumer read boom'); | ||
| 357 | + const throwResult = await iter.throw(err); | ||
| 358 | + assert.strictEqual(throwResult.value, undefined); | ||
| 359 | + assert.strictEqual(throwResult.done, true); | ||
| 360 | + | ||
| 361 | + await assert.rejects( | ||
| 362 | + () => readPromise, | ||
| 363 | + (e) => e === err, | ||
| 364 | + ); | ||
| 365 | + } | ||
| 366 | + | ||
| 329 | 367 | // end() while writes are pending rejects those writes | |
| 330 | 368 | async function testEndRejectsPendingWrites() { | |
| 331 | 369 | const { writer, readable } = push({ highWaterMark: 1, backpressure: 'block' }); | |
@@ -438,6 +476,8 @@ Promise.all([ | |||
| 438 | 476 | testConsumerThrowRejectsWrites(), | |
| 439 | 477 | testEndResolvesPendingRead(), | |
| 440 | 478 | testFailRejectsPendingRead(), | |
| 479 | + testConsumerReturnResolvesPendingRead(), | ||
| 480 | + testConsumerThrowRejectsPendingRead(), | ||
| 441 | 481 | testEndRejectsPendingWrites(), | |
| 442 | 482 | testEndIdempotentWhenClosed(), | |
| 443 | 483 | testEndRejectsWhenErrored(), | |
| Back | FazBrowse Home | New Git URL |
0 commit comments