* Put queue into terminal error state. * No-op if errored or closed (fully drained). * If closing (draining), short-circuits the drain.
(reason = kNoFailReason)
| 319 | * If closing (draining), short-circuits the drain. |
| 320 | */ |
| 321 | fail(reason = kNoFailReason) { |
| 322 | if (this.#writerState === 'errored' || this.#writerState === 'closed') { |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | const wasClosing = this.#writerState === 'closing'; |
| 327 | this.#writerState = 'errored'; |
| 328 | this.#error = reason === kNoFailReason ? |
| 329 | new ERR_INVALID_STATE('Failed') : |
| 330 | reason; |
| 331 | this.#cleanup(); |
| 332 | this.#rejectPendingReads(this.#error); |
| 333 | this.#rejectPendingDrains(this.#error); |
| 334 | |
| 335 | if (wasClosing) { |
| 336 | // Short-circuit the graceful drain: reject the pending end promise |
| 337 | if (this.#pendingEnd) { |
| 338 | this.#pendingEnd.reject(this.#error); |
| 339 | this.#pendingEnd = null; |
| 340 | } |
| 341 | } else { |
| 342 | this.#rejectPendingWrites(this.#error); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | get totalBytesWritten() { |
| 347 | return this.#bytesWritten; |
no test coverage detected