| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3b8c30c commit 4ba1fa0
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,6 +12,7 @@ const { | |||
| 12 | 12 | PromiseReject, | |
| 13 | 13 | PromiseResolve, | |
| 14 | 14 | PromiseWithResolvers, | |
| 15 | + Symbol, | ||
| 15 | 16 | SymbolAsyncDispose, | |
| 16 | 17 | SymbolAsyncIterator, | |
| 17 | 18 | SymbolDispose, | |
@@ -53,6 +54,8 @@ const { | |||
| 53 | 54 | RingBuffer, | |
| 54 | 55 | } = require('internal/streams/iter/ringbuffer'); | |
| 55 | 56 | ||
| 57 | + const kNoFailReason = Symbol('kNoFailReason'); | ||
| 58 | + | ||
| 56 | 59 | // ============================================================================= | |
| 57 | 60 | // PushQueue - Internal Queue with Chunk-Based Backpressure | |
| 58 | 61 | // ============================================================================= | |
@@ -315,14 +318,16 @@ class PushQueue { | |||
| 315 | 318 | * No-op if errored or closed (fully drained). | |
| 316 | 319 | * If closing (draining), short-circuits the drain. | |
| 317 | 320 | */ | |
| 318 | - fail(reason) { | ||
| 321 | + fail(reason = kNoFailReason) { | ||
| 319 | 322 | if (this.#writerState === 'errored' || this.#writerState === 'closed') { | |
| 320 | 323 | return; | |
| 321 | 324 | } | |
| 322 | 325 | ||
| 323 | 326 | const wasClosing = this.#writerState === 'closing'; | |
| 324 | 327 | this.#writerState = 'errored'; | |
| 325 | - this.#error = reason ?? new ERR_INVALID_STATE('Failed'); | ||
| 328 | + this.#error = reason === kNoFailReason ? | ||
| 329 | + new ERR_INVALID_STATE('Failed') : | ||
| 330 | + reason; | ||
| 326 | 331 | this.#cleanup(); | |
| 327 | 332 | this.#rejectPendingReads(this.#error); | |
| 328 | 333 | this.#rejectPendingDrains(this.#error); | |
@@ -398,7 +403,7 @@ class PushQueue { | |||
| 398 | 403 | return { __proto__: null, value: undefined, done: true }; | |
| 399 | 404 | } | |
| 400 | 405 | ||
| 401 | - if (this.#writerState === 'errored' && this.#error) { | ||
| 406 | + if (this.#writerState === 'errored') { | ||
| 402 | 407 | throw this.#error; | |
| 403 | 408 | } | |
| 404 | 409 | ||
@@ -473,7 +478,7 @@ class PushQueue { | |||
| 473 | 478 | } else if (this.#writerState === 'closed') { | |
| 474 | 479 | const pending = this.#pendingReads.shift(); | |
| 475 | 480 | pending.resolve({ __proto__: null, value: undefined, done: true }); | |
| 476 | - } else if (this.#writerState === 'errored' && this.#error) { | ||
| 481 | + } else if (this.#writerState === 'errored') { | ||
| 477 | 482 | const pending = this.#pendingReads.shift(); | |
| 478 | 483 | pending.reject(this.#error); | |
| 479 | 484 | } else if (this.#consumerState === 'returned') { | |
@@ -624,7 +629,7 @@ class PushWriter { | |||
| 624 | 629 | } | |
| 625 | 630 | ||
| 626 | 631 | fail(reason) { | |
| 627 | - this.#queue.fail(reason); | ||
| 632 | + this.#queue.fail(arguments.length === 0 ? kNoFailReason : reason); | ||
| 628 | 633 | } | |
| 629 | 634 | ||
| 630 | 635 | [SymbolAsyncDispose]() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -454,6 +454,39 @@ async function testEndRejectsWhenErrored() { | |||
| 454 | 454 | } | |
| 455 | 455 | } | |
| 456 | 456 | ||
| 457 | + async function testFailRejectsFutureReadWithFalsyReason() { | ||
| 458 | + for (const reason of [0, null]) { | ||
| 459 | + const { writer, readable } = push(); | ||
| 460 | + | ||
| 461 | + writer.fail(reason); | ||
| 462 | + | ||
| 463 | + const iter = readable[Symbol.asyncIterator](); | ||
| 464 | + await iter.next().then( | ||
| 465 | + common.mustNotCall(), | ||
| 466 | + common.mustCall((rejection) => { | ||
| 467 | + assert.strictEqual(rejection, reason); | ||
| 468 | + }), | ||
| 469 | + ); | ||
| 470 | + } | ||
| 471 | + } | ||
| 472 | + | ||
| 473 | + async function testFailRejectsPendingReadWithFalsyReason() { | ||
| 474 | + const { writer, readable } = push(); | ||
| 475 | + | ||
| 476 | + const iter = readable[Symbol.asyncIterator](); | ||
| 477 | + const readPromise = iter.next(); | ||
| 478 | + | ||
| 479 | + await new Promise(setImmediate); | ||
| 480 | + | ||
| 481 | + writer.fail(false); | ||
| 482 | + await readPromise.then( | ||
| 483 | + common.mustNotCall(), | ||
| 484 | + common.mustCall((reason) => { | ||
| 485 | + assert.strictEqual(reason, false); | ||
| 486 | + }), | ||
| 487 | + ); | ||
| 488 | + } | ||
| 489 | + | ||
| 457 | 490 | Promise.all([ | |
| 458 | 491 | testOndrain(), | |
| 459 | 492 | testOndrainNonDrainable(), | |
@@ -476,6 +509,8 @@ Promise.all([ | |||
| 476 | 509 | testConsumerThrowRejectsWrites(), | |
| 477 | 510 | testEndResolvesPendingRead(), | |
| 478 | 511 | testFailRejectsPendingRead(), | |
| 512 | + testFailRejectsFutureReadWithFalsyReason(), | ||
| 513 | + testFailRejectsPendingReadWithFalsyReason(), | ||
| 479 | 514 | testConsumerReturnResolvesPendingRead(), | |
| 480 | 515 | testConsumerThrowRejectsPendingRead(), | |
| 481 | 516 | testEndRejectsPendingWrites(), | |
| Back | FazBrowse Home | New Git URL |
0 commit comments