* Flushes all pending decode operations and waits for completion.
()
| 319 | * Flushes all pending decode operations and waits for completion. |
| 320 | */ |
| 321 | async flush() { |
| 322 | // Spec 4.5: If [[state]] is not "configured", return a promise rejected with InvalidStateError DOMException. |
| 323 | if (this._state !== 'configured') { |
| 324 | return Promise.reject(new DOMException('Decoder not configured', 'InvalidStateError')); |
| 325 | } |
| 326 | |
| 327 | // Spec 4.5: Set [[key chunk required]] to true. |
| 328 | this.keyChunkRequired = true; |
| 329 | |
| 330 | // Spec 4.5: Let promise be a new Promise. Append promise to [[pending flush promises]]. |
| 331 | return new Promise<void>((resolve, reject) => { |
| 332 | this.pendingFlushResolvers.push({ resolve, reject }); |
| 333 | |
| 334 | // Spec 4.5: Queue a control message to flush the codec... |
| 335 | this.flushInternal(this.currentConfigId, resolve).catch((e) => { |
| 336 | // If flush fails, we treat it as an error that closes the decoder |
| 337 | this.handleAsyncError(e); |
| 338 | }); |
| 339 | }); |
| 340 | } |
| 341 | |
| 342 | private async flushInternal(configId: number, resolve: () => void) { |
| 343 | using lock = this.mutex.lock(); |
nothing calls this directly
no test coverage detected