* Write chunks synchronously if possible. * Returns true if write completed, false if buffer is full. * @returns {boolean}
(chunks)
| 149 | * @returns {boolean} |
| 150 | */ |
| 151 | writeSync(chunks) { |
| 152 | if (this.#writerState !== 'open') return false; |
| 153 | if (this.#consumerState !== 'active') return false; |
| 154 | |
| 155 | if (this.#slots.length >= this.#highWaterMark) { |
| 156 | switch (this.#backpressure) { |
| 157 | case 'strict': |
| 158 | return false; |
| 159 | case 'block': |
| 160 | return false; |
| 161 | case 'drop-oldest': |
| 162 | if (this.#slots.length > 0) { |
| 163 | this.#slots.shift(); |
| 164 | } |
| 165 | break; |
| 166 | case 'drop-newest': |
| 167 | // Discard this write, but return true |
| 168 | for (let i = 0; i < chunks.length; i++) { |
| 169 | this.#bytesWritten += TypedArrayPrototypeGetByteLength(chunks[i]); |
| 170 | } |
| 171 | return true; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | this.#slots.push(chunks); |
| 176 | for (let i = 0; i < chunks.length; i++) { |
| 177 | this.#bytesWritten += TypedArrayPrototypeGetByteLength(chunks[i]); |
| 178 | } |
| 179 | |
| 180 | this.#resolvePendingReads(); |
| 181 | return true; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Write chunks asynchronously. |
no test coverage detected