| 104 | private abortHandler?: () => void; |
| 105 | |
| 106 | constructor(options: PushStreamOptions = {}) { |
| 107 | this.highWaterMark = Math.max(1, options.highWaterMark ?? 4); |
| 108 | this.backpressure = options.backpressure ?? 'strict'; |
| 109 | this.signal = options.signal; |
| 110 | |
| 111 | if (this.signal) { |
| 112 | if (this.signal.aborted) { |
| 113 | this.fail(this.signal.reason instanceof Error |
| 114 | ? this.signal.reason |
| 115 | : new DOMException('Aborted', 'AbortError')); |
| 116 | } else { |
| 117 | this.abortHandler = () => { |
| 118 | this.fail(this.signal!.reason instanceof Error |
| 119 | ? this.signal!.reason |
| 120 | : new DOMException('Aborted', 'AbortError')); |
| 121 | }; |
| 122 | this.signal.addEventListener('abort', this.abortHandler, { once: true }); |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | // =========================================================================== |
| 128 | // Writer Methods |