mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-28 19:33:51 +02:00
Add Output.cancel
This commit is contained in:
@@ -53,6 +53,8 @@ export class Output {
|
||||
/** @internal */
|
||||
_started = false;
|
||||
/** @internal */
|
||||
_canceled = false;
|
||||
/** @internal */
|
||||
_finalizing = false;
|
||||
/** @internal */
|
||||
_mutex = new AsyncMutex();
|
||||
@@ -150,6 +152,9 @@ export class Output {
|
||||
}
|
||||
|
||||
async start() {
|
||||
if (this._canceled) {
|
||||
throw new Error('Output has been canceled.');
|
||||
}
|
||||
if (this._started) {
|
||||
throw new Error('Output already started.');
|
||||
}
|
||||
@@ -168,6 +173,25 @@ export class Output {
|
||||
release();
|
||||
}
|
||||
|
||||
async cancel() {
|
||||
if (this._finalizing) {
|
||||
throw new Error('Cannot cancel after calling finalize.');
|
||||
}
|
||||
if (this._canceled) {
|
||||
throw new Error('Output already canceled.');
|
||||
}
|
||||
this._canceled = true;
|
||||
|
||||
const release = await this._mutex.acquire();
|
||||
|
||||
const promises = this._tracks.map(x => x.source._flush());
|
||||
await Promise.all(promises);
|
||||
|
||||
await this._writer.close();
|
||||
|
||||
release();
|
||||
}
|
||||
|
||||
async finalize() {
|
||||
if (!this._started) {
|
||||
throw new Error('Cannot finalize before starting.');
|
||||
|
||||
Reference in New Issue
Block a user