MCPcopy Create free account
hub / github.com/Vanilagy/webcodecs-polyfill / flush

Method flush

src/audio_decoder.ts:270–289  ·  view source on GitHub ↗

* Flushes all pending decode operations and waits for completion.

()

Source from the content-addressed store, hash-verified

268 * Flushes all pending decode operations and waits for completion.
269 */
270 async flush() {
271 // Spec: If [[state]] is not "configured", return a promise rejected with InvalidStateError DOMException.
272 if (this._state !== 'configured') {
273 return Promise.reject(new DOMException('Decoder not configured', 'InvalidStateError'));
274 }
275
276 // Spec: Set [[key chunk required]] to true.
277 this._keyChunkRequired = true;
278
279 // Spec: Let promise be a new Promise. Append promise to [[pending flush promises]].
280 return new Promise<void>((resolve, reject) => {
281 this._pendingFlushResolvers.push({ resolve, reject });
282
283 // Spec: Queue a control message to flush the codec...
284 this.flushInternal(this.currentConfigId, resolve).catch((e) => {
285 // If flush fails, we treat it as an error that closes the decoder
286 this.handleAsyncError(e);
287 });
288 });
289 }
290
291 private async flushInternal(configId: number, resolve: () => void) {
292 using lock = this.mutex.lock();

Callers 4

Calls 2

flushInternalMethod · 0.95
handleAsyncErrorMethod · 0.95

Tested by

no test coverage detected